Reputation: 41
Hello Friends i made an alert dialog box that is fired when there is no net connection and when person clicks the ok button he would be directed to No Internet.class it is working fine but real problem is when user click in background of alert dialog box it automatically dismissed.How can i stop that?? I mean cancelling of dialog box .I also used this method SetCancelable(false); but it is not working.It gives an error.
Below is my Code
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);
}
});
Upvotes: 0
Views: 4842
Reputation: 2260
Use setCancelable(false)
method. Hope it helps.
Upvotes: 2
Reputation: 2493
Just add alert.setCancelable(false);
. The reason why it was not working (from the comment in code) is, you were using wrong method name before.
AlertDialog.Builder alert = new AlertDialog.Builder(...);
alert.setCancelable(false); // not SetCancelable(false). Case sensitive
});
Upvotes: 9
Reputation: 1938
Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(false);
Upvotes: 3