[英]Removing items from a ListAdapter not working
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Remove"){
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
quotesAdapter.remove(quotes.get((int)info.id));
quotesAdapter.notifyDataSetChanged();
listView.setAdapter(quotesAdapter);
serializeQuotes();
}
else {
return false;
}
return true;
}
Doesn't do anything. 什么也没做 If I add
如果我加
this.quotesAdapter = new QuoteAdapter(this, R.layout.mainrow, quotes);
Removal works, but I don't think is the right way of doing things. 拆除工作有效,但我认为这不是正确的处理方式。 I'm not sure what is wrong?
我不确定出什么问题了吗?
If quotes
is a Java array, that is unmodifiable at runtime. 如果
quotes
是Java数组,则在运行时无法修改。 Try using an ArrayList<>
instead. 尝试改用
ArrayList<>
。
If quotes
is a Cursor
, you need to delete the row from the underlying database, then requery()
the Cursor
. 如果
quotes
是Cursor
,则需要从基础数据库中删除该行,然后重新requery()
Cursor
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.