当我要求用户删除不是的项目时,我有很好的工作代码。AlertDialog不希望被显示
case R.id.item_Delete:
Log.d("TAG","Deletion ...");
AlertDialog.Builder delAllDialog = new AlertDialog.Builder(this);
delAllDialog.setTitle("Confirm deletion");
TextView dialogTxt_id = new TextView(this);
LayoutParams dialogTxt_idLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
dialogTxt_id.setLayoutParams(dialogTxt_idLayoutParams);
dialogTxt_id.setText("Delete?");
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(dialogTxt_id);
delAllDialog.setView(layout);
delAllDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
delete();
}
});
break;
...
它很好用! 我只是复制这个和平的代码,并把它放在另一个类似的活动,在相同的菜单代码。 而我在我的日志中有Deletion..
,然后什么也没有发生。 LogCat清楚,没有错误。
我搜索并找到其他几个相同的问题(例如Android - AlertDialog doesn't show when called from Main-Method),但也没有清理项目,也没有其他的东西不能解决我的问题.. 任何想法?
没有delAllDialog.show()在你发布的代码。这可能是问题 – Darussian 2013-03-21 20:31:25
谢谢你,对我感到羞耻。 – Foenix 2013-03-21 20:54:09