2011-08-09 22 views
0

私が活動中で、コードのこの部分を使用しています:私は需要を削除した後、リストビューをリフレッシュしたいAndroidでリストビューを更新するにはどうすればよいですか?

public void onClick(View v) { 
      AlertDialog alertDialog = new AlertDialog.Builder(ctx).create(); 
      alertDialog.setTitle("Do you wanna delete?"); 
      alertDialog.setIcon(R.drawable.icon); 
      alertDialog.setMessage("if 'yes' the demand '" 
        + dem.getNr_demanda() + "' will be deleted!"); 
      alertDialog.setButton("OK", 
        new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, 
         int which) { 
        // if yes delete, and REFRESH the screen 
        DemandaDAO dbHelper; 
        try { 
         dbHelper = new DemandaDAO(ctx); 
         dbHelper.DeleteDem(dem);        
        } catch (FileNotFoundException e) { 
         e.printStackTrace(); 
        }} 
      }); 
      alertDialog.setButton2("Cancel", 
        new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, 
         int which) { 
        return; 
       } 
      }); 
      alertDialog.show(); 
     } 
    }); 

、しかし:

 public void carregaListaDemanda(){ 
     setContentView(R.layout.listaviewdemanda); 
     lstDem = (ListView) findViewById(R.id.listViewDemanda); 
    DemandaAdapter adapter = new DemandaAdapter(ctx, 
      bancodedados.getAllDem(), this); 
    lstDem.setAdapter(adapter); 
    lstDem.setItemsCanFocus(true); 
    teste=0; 
} 

とアダプタで私は再びアクティビティのメソッドを呼び出すとforcecloseになります。

+0

エラーのlogcatトレースを投稿しようとしています –

+0

エラーコードとエラーの種類を取得できるようにlogcatを表示してください。 –

答えて

2

call adapter.notifyDataSetChanged()、それは、基になるデータが変更され、それ自体を更新する必要があることを添付ビューに通知します。

関連する問題