【发布时间】:2011-10-23 11:52:37
【问题描述】:
我在活动中使用了这段代码:
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;
}
在适配器中:
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();
}
});
我想在删除一个需求后刷新列表视图,但是如果我再次在活动中调用该方法会导致强制关闭。
【问题讨论】:
-
总是尝试发布错误的 logcat 跟踪
-
请显示 logcat,以便我们了解您在哪里出错以及错误类型。