所以我在 listView 中显示了一个数据库。当我删除一个项目时,我试图让列表更新和删除该项目。我有所有代码并且没有收到任何错误。我只是不刷新列表。
这是我所拥有的:
public void Requery() {
db.open();
final Cursor c1 = DBAdapter.getAllRecords();
startManagingCursor(c1);
String[] from = new String[] { DBAdapter.KEY_ITEM };
int[] to = new int[] { R.id.text1 };
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.row,
c1, from, to);
setListAdapter(notes);
c1.getCursor().requery(); //trying to refresh list
db.close();
}
我也试过:
public void Requery() {
db.open();
final Cursor c1 = DBAdapter.getAllRecords();
startManagingCursor(c1);
String[] from = new String[] { DBAdapter.KEY_ITEM };
int[] to = new int[] { R.id.text1 };
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.row,
c1, from, to);
setListAdapter(notes);
notes.notifyDataSetChanged(); //another way that still didn't work
db.close();
}
我在这里错过了什么吗?