Android-click the button in the dialog box to not close the dialog box. android button

Source: Internet
Author: User

Android-click the button in the dialog box to not close the dialog box. android button

Sometimes I do not need to click the button for some detection, but do not want to close the dialog box (the system click any button by default to close the dialog box). The solution is as follows: add the following code under the click event:

 

 

Java code  
  1. Try
  2. {
  3. Field field = dialog. getClass ()
  4. . GetSuperclass (). getDeclaredField (
  5. "MShowing ");
  6. Field. setAccessible (true );
  7. // Set the mShowing variable to false, indicating that the dialog box is closed.
  8. Field. set (dialog, false );
  9. Dialog. dismiss ();
  10. }
  11. Catch (Exception e)
  12. {
  13. }

Click the button to add the above Code to the Event code, and the button will no longer be able to close the dialog box. To close the dialog box, set mShowing to true. Note that setting the mShowing variable in one button also affects the function of closing the dialog box of another button. Therefore, you need to set the mShowing variable value in the click event of each button.

 

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.