【发布时间】:2011-11-04 05:54:56
【问题描述】:
在我的代码中,我有一个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();
任何帮助表示赞赏。 谢谢!
【问题讨论】: