在我的代码中我有一个ListActivity
。列表项的其中一个上下文菜单选项是“删除”,它将打开一个对话框,确认该操作。我打算通过首先删除数据库中的项目数据然后从ArrayAdapter
中删除它来实现此功能。它是从ArrayAdapter
删除它,我得到了UnsupportedOperationException
...UnsupportedOperationException与ArrayAdapter.remove
public void onClick(DialogInterface dialog, int id)
{
asynchronousDeleteEntry(CONTEXT_SELECTED_ID);
dialog.dismiss();
//I -know- that the adapter will always be an object
//of ArrayAdapter<JournalEntry> because this is the only type
//I ever call setListAdapter with. Debugging confirms this
@SuppressWarnings("unchecked")
final ArrayAdapter<JournalEntry> adapter = (ArrayAdapter<JournalEntry>)
journalViewerListActivity.this.getListAdapter();
//EXCEPTION OCCURS HERE
adapter.remove(adapter.getItem(CONTEXT_SELECTED_POSITION));
//refreshes the ListView to show the new items
adapter.notifyDataSetChanged();
赞赏任何帮助。 谢谢!
这不是“最终”的意思。它与C++“const”不一样。 – mhsmith