在我的代碼中我有一個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