在我的代码中,我有一个 ListActivity。列表项的上下文菜单选项之一是“删除”,它会打开一个对话框以确认操作。我打算通过首先从数据库中删除该项的数据,然后从 ArrayAdapter 中删除该项来实现此功能。正是在从 ArrayAdapter 中删除该项时,我遇到了 UnsupportedOperationException 异常...
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();
非常感谢您提供帮助。
谢谢!