我有一个WCF女巫提供一些JSON数据,然后我将其保存到本地数据库.工作正常我有一个活动女巫将数据从本地数据库填充到listview女巫工作正常.
public void fillData() {
// Fields from the database (projection)
// Must include the _id column for the adapter to work
String[] from = new String[] { TodoTable.COLUMN_SUMMARY };
// Fields on the UI to which we map
int[] to = new int[] { R.id.label };
getLoaderManager().initLoader(0, null, this);
adapter = new SimpleCursorAdapter(this, R.layout.todo_row, null, from,
to, 0);
lw.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚在从WCF执行同步操作之前删除所有行的最佳方法是什么.
我可以通过从数据库中获取所有Id然后找到行URI然后使用:
getContentResolver().delete(uri, null, null)
Run Code Online (Sandbox Code Playgroud)
我只是认为必须有更好的方法我在网上看到许多使用DbHelper类的例子,但我无法弄清楚如何从Activity或ContentProvider访问dbHelper类
希望这是有道理的
Kri*_*her 29
使用DatabaseHelper你可以这样做:
dbHelper = new DatabaseHelper(context);
database = dbHelper.getWritableDatabase();
public void clearTable() {
database.delete(TABLE, null,null);
}
Run Code Online (Sandbox Code Playgroud)
尝试
<your-SQLite-instance>.execSQL("DELETE FROM <table_name>");
Run Code Online (Sandbox Code Playgroud)
这将删除所有行 <table_name>