Android Alert dialog Fix the Click button dialog box does not close the issue

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.