0

I m planning to create a android app. And for a part of this project i have to have a Sqlite database including some record from the first time of installing apk file to the device...

For searching the cities of a country i should put data into the table of sqlite database from the first

I dont want to get data from internet or xml file Just i want to know is it possile to have a table with some record from the first of installing this apk??

Is it possible to do this???

I know how to create new database and table but i dont know how to add a complete sqlite database with data in it to the project

4

4 回答 4

1

Are you using a class that extends SQLiteOpenHelper to create your database? You can insert records into your table in onCreate records. This way the records will be available from the start.

于 2013-09-30T20:57:59.750 回答
1

import your database into the assets folder. Use in you database helper to access it:

getBaseContext().getAssets().open("myfile.db")
于 2013-09-30T20:59:26.173 回答
1

have you tried to insert data in the onCreate method of your SQLiteOpenHelper class? this method just gets called the first time the database gets created. so you should be able to add date there

于 2013-09-30T21:06:30.417 回答
1

Just i want to know is it possile to have a table with some record from the first of installing this apk?

Use SQLiteAssetHelper to package a database with your app and position it properly on first use after install.

于 2013-09-30T21:15:38.340 回答