This question already has answers here:
How to avoid dismissing my progress dialog when the user touches the screen?
(6 answers)
Closed 8 years ago.
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 alert dialog it just disappear, and nothing will happen, Is there any way to prevent dialog from disappearing when user clicked somewhere else???
Prevent dismiss dialog box on outside touch use this
dialog.setCanceledOnTouchOutside(false);
Add this line to your AlertDialog..
alertDialog.setCanceledOnTouchOutside(false);
For more read here Dialog cancel
You must give this line.
alertDialog.setCanceledOnTouchOutside(false);
on bottom of the your AlertDialog.
Yes Use
YourAlertDialog.setCanceledOnTouchOutside(false);
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.
I usually use the combination of:
alertDialog.setCancelable(false);
alertDialog.setCanceledOnTouchOutside(false);
Related
I'm trying to close a dialog on click outside, but when I click on the area of the left or right side of dialog it doesn't get closed. I researched it a bit, and figured out that it's the padding of DecorView that creates that transparent space on sides, but I haven't found any way to make it clickable
Close AlertDialog when window padding area clicked
Sorry, you can't do this. Its not possible AFAIK. You should try with setCanceledOnTouchOutside
Sets whether this dialog is canceled when touched outside the window's
bounds. If setting to true, the dialog is set to be cancelable if not
already set.
dialogOBJ.setCanceledOnTouchOutside(true);
Do you try cancel on outside touch function like this
dialog.setCanceledOnTouchOutside(true);
Try to add this line to your dialog:
dialog.setCanceledOnTouchOutside(true);
And now the dialog will get closed when the user will click the screen.
Try this:
alertDialog.setOnTouchListener{
alertDialog.dismiss()
}
There is a Dialog Box, how can I prevent it from being dismissed? I want not only the user enter a username but also prevent him/her from leaving the box empty?
dialog.setCancelable(false);
This function call will make your dialog dismissable by touch on the outside of the dialog. Moreover, you can control the actions of the positive and negative buttons. However if you have custom dialog with edit text in it then you should check the string that you get from edittext when user click the positive or negative button and not call dialog.dismiss(); method if string is empty. Hope it helps.
Try this code, it prevents user from dismissing the dialogue box
myDialog.setCancelable(false);
This question already has answers here:
Prevent Android activity dialog from closing on outside touch
(20 answers)
Closed 6 years ago.
I need to lock my AlertDialog. Now, when my alertDialog is enable and when i click on the screen, my alertdialog closed. I need to wait the end of the progress bar to close my alertDialog. How i can do this? Thank
You just need to use alertdialog.setCancelable(false) so the dialog does not close when the user touches elsewhere on the screen, or touches the back button on their phone. After your progress bar completes, call alertdialog.dismiss() to close it.
I am using alert dialog in my android app, which has a YES and a NO button.
I want the alert to close on clicking either YES or NO, but it is closing touch everywhere in the screen how to stop it.
Have you tried Dialog.setCanceledOnTouchOutside(false) ?
http://developer.android.com/reference/android/app/Dialog.html#setCanceledOnTouchOutside(boolean)
Suppose you have an AlertDialog with two buttons A and B. I have found that on some devices and some versions of android, if you touch any area of the screen around the dialog, the AlertDialog disappears. On other devices you are forced to select either A or B, so there is no way I can allow the user to cancel the action without adding a third ('Cancel') option to the AlertDialog. Is there any way to determine programmatically whether the third option is required?
You can control it with dialog.setCanceledOnTouchOutside(true);
For more information :
How to dismiss the dialog with click on outside of the dialog?
Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(true);