我有一个ListAdapter
这是用来显示在Listview
列表。现在我添加了一个longpress菜单操作来删除任何选定的项目。Android的ListAdapter没有更新
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()
,但它不起作用。概率的解决方案是什么?
你确定底层的数据是通过'deleteRes(wordId);'来删除吗? – xandy 2011-04-06 06:22:04
数据正在被正确删除......如果我去另一个区域......并回到那个区域......它会给出正确的列表。 – 2011-04-06 06:33:38
也许你可以发布更多的代码,比如适配器,看看有什么问题。 – xandy 2011-04-06 07:41:19