【发布时间】:2016-04-09 09:44:44
【问题描述】:
你好朋友我做了一个警告对话框,当没有网络连接时触发,当人们点击确定按钮时,他将被定向到 No Internet.class 它工作正常,但真正的问题是当用户点击背景时警报对话框自动关闭。我怎样才能阻止它? 我的意思是取消对话框。我也使用了这个方法 SetCancelable(false);但它不起作用。它给出了一个错误。
下面是我的代码
AlertDialog.Builder alert = new AlertDialog.Builder(this,R.style.AppCompatAlertDialogStyle);
alert.setTitle("Internet Problem");
alert.setMessage("No Internet!!!");
// alert.SetCancelable(false);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//Do something here where "ok" clicked and then perform intent from activity context
Intent intent = new Intent(BaseActivity.this, NoInternet.class);
BaseActivity.this.startActivity(intent);
}
});
【问题讨论】:
-
Prevent Android activity dialog from closing on outside touch 的可能重复项。但请务必阅读所有答案。有很多投票高于接受。