2011-08-26 13 views
4

私のコードにはListActivityがあります。リストアイテムのコンテキストメニューオプションの1つが「削除」で、アクションを確認するダイアログが開きます。私は最初にデータベース内のアイテムのデータを削除してからArrayAdapterから削除することで、この機能を実装しようとしました。それは私が感謝すべてのヘルプUnsupportedOperationException ...ArrayAdapter.removeを使用した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(); 

を得ることArrayAdapterから削除しています。 ありがとう!

答えて

-1

finalと宣言されているリストを変更しようとしています。コンパイラはあなたに警告しようとしましたが、警告を表示しませんでした。@SuppressWarnings("unchecked")

+0

"最終"の意味ではありません。これはC++の "const"と同じではありません。 – mhsmith

関連する問題