我有一個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