Skip to content Skip to sidebar Skip to footer

Android: Alertdialog - User Click Somewhere Else

I have an Alert-dialog with 2 buttons( Yes/No ) If user click yes or no the alert dialog behave normal and get into on-click method, but if user click or touch somewhere outside of

Solution 1:

Add this line to your AlertDialog..

alertDialog.setCanceledOnTouchOutside(false);

For more read here Dialog cancel

Solution 2:

You must give this line.

alertDialog.setCanceledOnTouchOutside(false);

on bottom of the your AlertDialog.

Solution 3:

Yes Use

YourAlertDialog.setCanceledOnTouchOutside(false);

Solution 4:

use

alertDialog.setCanceledOnTouchOutside(false);

also you can use given below line for a practice that alert dialog can only go away by pressing the buttons

 alertDialog.setCancelable(false). 

This will make it so it can only go away by pressing the buttons.

Solution 5:

I usually use the combination of:

alertDialog.setCancelable(false); 
alertDialog.setCanceledOnTouchOutside(false);

Post a Comment for "Android: Alertdialog - User Click Somewhere Else"