gpt4 book ai didi

Android ListAdapter 没有更新

转载 作者:行者123 更新时间:2023-11-30 04:43:17 26 4
gpt4 key购买 nike

我有一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com