2011-08-26 85 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

相關問題