我做如下的事情:
public class WhitelistActivity extends ListActivity {
private DbAdapter dbHelper;
private SimpleCursorAdapter adapter;
private Cursor recordsCursor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.whitelist);
dbHelper = new DbAdapter(this);
dbHelper.open();
recordsCursor = dbHelper.fetchWhitelistRecords();
startManagingCursor(recordsCursor);
String[] from = new String[]{DbAdapter.KEY_W_SENDER};
int[] to = new int[]{R.id.text1};
adapter = new SimpleCursorAdapter(this, R.layout.whitelist_row, recordsCursor, from, to);
setListAdapter(adapter);
...
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case CONTEXT_MENU_DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
dbHelper.deleteWhitelistRecord(info.id);
adapter.changeCursor(recordsCursor);
adapter.notifyDataSetChanged();
return true;
}
return super.onContextItemSelected(item);
}
但是,当调用上下文菜单并删除项目时,它不会反映在列表视图中。我错过了什么?