简体   繁体   中英

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. 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. Final is an absolute layout, where i have placed an OK button.

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 . Use RelativeLayout instead. 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.

You create a helper class extending the Android-provided SQLiteOpenHelper and override the onCreate. Then just create an instance of that class inside your main Activity. For the example on the webpage, this would be:

DictionaryOpenHelper mSQL = new DictionaryOpenHelper(this);

Then you can call getWriteableDatabase(); and 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. 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):

/** 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.

对于数据库表中创建一起来看看这个 ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM