0
我在Android中遇到问题,当我设置适配器时,列表视图未更新。 这一点,我用它来从数据库中删除一个注释:Android列表视图问题
listaNotas.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, final long id) {
AlertDialog.Builder dialogo = new AlertDialog.Builder(Main.this);
dialogo.setTitle("Confirmação");
dialogo.setMessage("Deseja mesmo deletar a nota?");
dialogo.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
db.delete("Notas", "_id=?", (new String[]{String.valueOf(id)}));
Toast.makeText(Main.this, "Nota deletada com sucesso!", 5).show();
atualizaNota();
return;
}
});
dialogo.setNegativeButton("Não", null);
dialogo.show();
return false;
}
});
,这是适配器的更新:
public void atualizaNota() {
Cursor c = db.query("Notas", (new String[]{"_id", "Nota"}), "fgCompromisso=?", (new String[]{"0"}), null, null, "_id DESC");
if (c.getCount()==0)
return;
String[] from = {"Nota"};
int[] to = {R.id.edDescNota};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(Main.this, R.layout.layoutlistanota, c, from, to);
listaNotas.setAdapter(adapter);
}
那里的代码中的任何问题吗?
其实我是非常愚蠢的,我只有一个音符并将其删除,感觉如下: – JLFerrari
if(c.getCount()== 0) return; 然后,只是不要更新适配器....我的愚蠢是令人难以置信的。 ; D 但你的答案帮了很大忙! = d – JLFerrari