[英]How to store in database in android
In my application i have created an application form. 在我的应用程序中,我创建了一个申请表。 In one of the page, i have placed 4 layouts.First is to be the root Absolute layout where the background image placed.
在其中一个页面中,我放置了4个布局。首先是放置背景图像的根绝对布局。 2nd is the table layout in which i have placed 3 edit text boxes, next is an absolute layout where i am trying to display the latitude and longitude value.
第二个是表布局,其中我放置了3个编辑文本框,接下来是绝对布局,我试图显示纬度和经度值。 Final is an absolute layout, where i have placed an OK button.
决赛是一个绝对的布局,我已经放置了一个OK按钮。
if the ok button is pressed i want to create a database for the data entered in the edit text box and the longitude latitude values 如果按下确定按钮,我想为编辑文本框中输入的数据和经度纬度值创建数据库
how to create a database for the data entered in the edit text boxes... 如何为编辑文本框中输入的数据创建数据库...
pls help me.. 请帮助我..
1) AbsoluteLayout is deprecated . 1) 弃用 AbsoluteLayout。 Use RelativeLayout instead.
请改用RelativeLayout。 http://developer.android.com/reference/android/widget/AbsoluteLayout.html
http://developer.android.com/reference/android/widget/AbsoluteLayout.html
2) http://developer.android.com/guide/topics/data/data-storage.html#db pretty much covers the DB creation. 2) http://developer.android.com/guide/topics/data/data-storage.html#db几乎涵盖了数据库的创建。
You create a helper class extending the Android-provided SQLiteOpenHelper and override the onCreate. 您创建一个辅助类,扩展Android提供的SQLiteOpenHelper并覆盖onCreate。 Then just create an instance of that class inside your main Activity.
然后在主Activity中创建该类的实例。 For the example on the webpage, this would be:
对于网页上的示例,这将是:
DictionaryOpenHelper mSQL = new DictionaryOpenHelper(this);
Then you can call getWriteableDatabase();
然后你可以调用
getWriteableDatabase();
and getReadadableDatabase();
和
getReadadableDatabase();
on that object. 在那个对象上。
SQLiteDatabase db = mSQL.getWriteableDatabase();
Then you just use the built-in functionality to insert values which you will grab from your EditText fields. 然后,您只需使用内置功能插入您将从EditText字段中获取的值。 An example of how the insert statement looks for me (I run it in a background thread now though, to avoid doing Database-intensive things on the UI thread):
insert语句如何查找我的示例(我现在在后台线程中运行它,以避免在UI线程上执行数据库密集型操作):
/** SQL insert statement */
private void addIP(String string) {
SQLiteDatabase db = sql.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(IP_DB, string);
values.put(TIME, System.currentTimeMillis());
db.insert(TABLE_NAME, null, values);
}
Read up on Databases in Android and you'll be fine. 阅读Android中的数据库,你会没事的。
对于数据库表中创建一起来看看这个 ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.