2011-08-09 6 views
0

J'utilise ces morceaux de code, dans l'activité:Comment rafraîchir un listview sur Android?

 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; 
} 

et l'adaptateur:

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(); 
     } 
    }); 

Je veux rafraîchir la listview après la suppression d'une demande, mais il en résulte un forceclose si j'appelle à nouveau la méthode en activité.

+0

toujours essayer de poster la trace logcat de votre erreur –

+0

S'il vous plaît montrer le logcat afin que nous puissions obtenir où obtenez-vous erreur et quel type d'erreur. –

Répondre

2

appel adaptateur.notifyDataSetChanged(), il Notifie la vue attachée que les données sous-jacentes ont été modifiées et qu'il doit s'actualiser.

Questions connexes