How does android make the pop-up dialog box disappear? android dialog box

Source: Internet
Author: User

How does android make the pop-up dialog box disappear? android dialog box

Builder builder = new AlertDialog. Builder (this );
Builder. setTitle (android. R. string. dialog_alert_title)
. SetIcon (android. R. drawable. ic_dialog_info)
. SetPositiveButton (android. R. string. OK,
New OnClickListener (){
Public void onClick (DialogInterface dialog,
Int which ){

// Do not disappear
Try {
Java. lang. reflect. Field field = dialog
. GetClass (). getSuperclass ()
. GetDeclaredField ("mShowing ");
Field. setAccessible (true );
Field. set (dialog, false );
} Catch (Exception e ){
E. printStackTrace ();
}
}
})
. SetNegativeButton (android. R. string. no,
New OnClickListener (){
Public void onClick (DialogInterface dialog,
Int which ){

// Disappear
Try {
Java. lang. reflect. Field field = dialog
. GetClass ()
. GetSuperclass ()
. GetDeclaredField ("mShowing ");
Field. setAccessible (true );
Field. set (dialog, true );
} Catch (Exception e ){
E. printStackTrace ();
}
Dialog. dismiss ();
}
}). Show ();

After testing, we found that the dialog box disappears if you click a place other than "OK", but if you click "OK" and then click a place other than the dialog box, it will not disappear.

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.