更新时间:2023-02-02 21:57:47
请参阅的http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/.
您可以precreate数据库和复制precreated版本,一旦用户重新设置表。
希望这有助于。
感谢。
So I have a database in the assets folder. I copy this over when the app is first run. The database contains three tables unrelated.
However, I have buttons to reset data for each list (where data is stored in a table), so is it possible to delete the current table and then copy the stored one across? Or something along those lines, maybe overwrite the old table with the new one? (The reason I wish to do it this way is because it's much quicker to copy that to carry out hundreds of insert operations!)
The current methods I have so far are:
In the DatabaseHelper class:
public void recreateTable(String tableName) {
// Logic for removing old table and inserting new one goes here
}
In the class for editing the list displayed
public void resetList() {
DatabaseHelper dbhp = new DatabaseHelper(this);
dbhp.open();
recreateTable("STC");
Toast.makeText(generalContext, "List Reset!", Toast.LENGTH_LONG).show();
dbhp.close();
}
Please see http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/.
You can precreate your database and copy the precreated version, once the user resets the table.
Hope this helps.
Thanks.