【发布时间】:2013-03-21 20:28:59
【问题描述】:
当我要求用户删除项目时,我有很好的工作代码。
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() 。这可能是问题
标签: android android-alertdialog