Android Alertdialog in the left and right three buttons, click on the button, even if the dismiss method is not called, the system will be called by default, and this dialog is closed, but some of our actual needs, we need to keep this dialog box, such as input check code, Password, such as the verification problem, if the user entered an error, and closed after the dialog box, it is very awkward. There is a solution to this problem so that even if the button event occurs, the dialog box is not closed. The core idea is to deceive the system, in the Click event, modify the display status of the dialog box is closed, the system will not go to close the dialog box. The specific implementation code is as follows:
/** @author sanji* Assume that the dialog box has been closed to deceive the system to keep the input window */
private void Setdialognotshow () {
if (mdialoginterface!=null) {
try {
Field field = Mdialoginterface.getclass (). Getsuperclass (). Getdeclaredfield ("mshowing");
Field.setaccessible (TRUE); Set the mshowing variable to false to indicate that the dialog box is closed
Field.set (Mdialoginterface, false);
} catch (Exception e) {
E.printstacktrace ();
}
}
}
Mdialoginterface is the Dialoginterface dialog parameter that is passed in by clicking the Dialog button event, if you need to destroy the dialog box again:
private void Closedialogofpinorpuk () {
if (mdialoginterface!=null) {
try {
Field field = Mdialoginterface.getclass (). Getsuperclass (). Getdeclaredfield ("mshowing");
Field.setaccessible (TRUE);
Field.set (Mdialoginterface, true);
Mdialoginterface.dismiss ();
}catch (Exception e) {
E.printstacktrace ();
}
}
}
Android Alert dialog Fix the Click button dialog box does not close the issue