我有一个 ListAdapter
,用于在 Listview
中显示列表。现在我添加了一个长按菜单操作来删除任何选定的项目。
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item
.getMenuInfo();
final Long wordId = menuInfo.id;
// selected_row = menuInfo.position;
// To get the id of the clicked item in the list use menuInfo.id
switch (item.getItemId()) {
case CONTEXT_DELETE:
deleteRes(wordId); // delete function for the item
break;
default:
return super.onContextItemSelected(item);
}
//((BaseAdapter) favAdapter).notifyDataSetChanged();
return true;
}
但删除后列表正在更新并显示包含已删除项目的旧列表。我尝试使用 notifyDataSetChanged()
,但它不起作用。问题的解决方案是什么?
最佳答案
我用了下面的代码,问题解决了。
favCursor = wordDataHelper.getCursorFav();
((SimpleCursorAdapter) favAdapter).changeCursor(favCursor);
关于Android ListAdapter 没有更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5562191/