Ana
Ana

Reputation: 41

The alert dialog disappears

I want to do an alert dialog in an Android app. When I put the setPositiveButton and setNegativeButton all is right but when I click on the background, the alert dialog disappears and this functionality I don't want it. I need that the user only can choose two possibilities and when the user touch the background, the alert dialog doesn't disappear.

Upvotes: 0

Views: 524

Answers (2)

Enough Technology
Enough Technology

Reputation: 795

To prevent dialog box from getting dismissed on back key pressed use this

dialog.setCancelable(false);

And to prevent outside touch use this

dialog.setCanceledOnTouchOutside(false);

Upvotes: 1

Michael Celey
Michael Celey

Reputation: 12745

You want to make sure your AlertDialog is not cancelable.

alertDialogBuilder.setCancelable(false);

Check the documentation here.

Upvotes: 0

Related Questions