-2

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Benjamin
  • 1
  • 1
  • Specify your own OnClickListeners using the `AlterDialog.Builder`'s `setPositiveButton`/`setNegativeButton`. You could also change the buttons' enable state dynamically based on the input fields' contents. – Michael Aug 02 '18 at 12:39
  • You can also make customise dialog box, it wont be dismissed until you do it yourself – makkhokher Aug 02 '18 at 12:41
  • Duplicate OF [How to prevent a dialog from closing when a button is clicked](https://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked). – ADM Aug 02 '18 at 12:55

2 Answers2

3
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.

Alperen Kantarcı
  • 1,038
  • 9
  • 27
0

Try this code, it prevents user from dismissing the dialogue box

myDialog.setCancelable(false);