【发布时间】:2014-12-20 14:25:13
【问题描述】:
我在做什么:
- 我正在使用以下代码启动一个对话框
- 点击我想关闭对话框
发生了什么;
- 对话框正在关闭,但我必须单击两次确定按钮(看起来警报弹出两次,但我第二次按确定关闭)
我想做什么:
- 我想在第一次点击确定时关闭对话框
public void open(String custMsg){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage(custMsg);
alert.setCancelable(false);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
});
alert.show();
}
【问题讨论】:
-
打电话给
dialog.dismiss()而不是dialog.cancel(); -
我试过但结果相同!....正如我所说,对话框将关闭,但如果弹出两次看起来像对话框本身......
-
在您打开对话框的位置显示该事件..
-
在 onResume() 中我弹出了这个警告对话框
-
好吧,这就是问题所在。因为每次在您的活动中,您的 onResume() 都会调用并弹出。
标签: android android-alertdialog