In Android Alertdialog, you can close the dialog box by using the button that comes with it, clicking OK or Cancel. However, we sometimes hope that when we click OK to find that he has not filled out the option, we prompt him to fill in the complete, this time do not close the dialog box. Of course, there are a lot of solutions. Like using an activity to do dialog. or customize view. Use the button you have defined. Do not use the button that comes with it. But sometimes our dialog view is simple, and we continue to use our own button at this time. What to do at this time. Can take advantage of Java's reflection technology. Place the button where it needs not to be closed:
try {Field field = Dialog.getclass (). Getsuperclass (). Getdeclaredfield ("mshowing"); Field.setaccessible (true);// Set the mshowing variable to false to indicate that the dialog box is closed Field.set (dialog, false);d Ialog.dismiss ();} catch (Exception e) {e.printstacktrace ();}
Where you need to close:
try {Field field = Dialog.getclass (). Getsuperclass (). Getdeclaredfield ("mshowing"); Field.setaccessible (true);// Set the mshowing variable to false to indicate that the dialog box is closed Field.set (dialog, True);d Ialog.dismiss ();} catch (Exception e) {e.printstacktrace ();}
Here's the Field where the package is Java.lang.reflect.Field
Refer to this article for specific details: http://blog.csdn.net/notonlyforshe/article/details/7955323
Android Let Alertdialog Click OK won't disappear