2011-08-26 33 views
4

在我的代码中我有一个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(); 

赞赏任何帮助。 谢谢!

回答

-1

您正在尝试修改声明为final的列表。编译器试图警告你,但你已经禁止了警告@SuppressWarnings("unchecked")

+0

这不是“最终”的意思。它与C++“const”不一样。 – mhsmith

相关问题