调用requery()或notifyDataSetChanged时,ListView不会刷新

时间:2013-09-09 15:50:29

标签: android android-sqlite

所以我在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();
}

我在这里错过了什么吗?

0 个答案:

没有答案