I want to create a database starts with the data. I'm creating a app that has a long list of items.
I have used:
String item1 = "my item";
ContentValues cvItems = new ContentValues();
cvM1.put(KEY_NAME, item1);
db.insert(DATABASE_TABLE, null, cvItems);
but I think that having to use a string for each element is too much and there has to be a shorter way. And I want to know if its possible to start with a database that has all values predefined. Also I can't reference strings from strings xml in SQL. thanks in advance
Your best approach is probably to create a template database that contains all the data you need and restore a full copy of the DB from the template rather that building it incrementally. Then just tweak whatever items you need to in code to suit the particular usage of that instance of the DB.
This will make it easier to change the default data without updating your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With