Android makes AlertDialog click OK, and androidalertdialog

Source: Internet
Author: User

Android makes AlertDialog click OK, and androidalertdialog

In alertDialog of Android, use the built-in button and click OK or cancel to close the dialog box. However, we sometimes want to click "OK" to find that there is a blank option, and we will prompt him to fill it out completely. At this time, the dialog box will not be closed. Of course there are many solutions. For example, a single activity is used as a dialog. Or custom view. use the Custom button. do not use the built-in button. however, sometimes our dialog view is very simple. At this time, we continue to use the built-in button. what should we do at this time. Java reflection technology that can be used. Where the button does not need to be closed:

Try {Field field = dialog. getClass (). getSuperclass (). getDeclaredField ("mShowing"); field. setAccessible (true); // set the mShowing variable to false, indicating that the field is closed in the dialog box. set (dialog, false); dialog. dismiss ();} catch (Exception e) {e. printStackTrace ();}

Where you need to disable the service:

Try {Field field = dialog. getClass (). getSuperclass (). getDeclaredField ("mShowing"); field. setAccessible (true); // set the mShowing variable to false, indicating that the field is closed in the dialog box. set (dialog, true); dialog. dismiss ();} catch (Exception e) {e. printStackTrace ();}

The Field package here is java. lang. reflect. Field

Specific details can refer to this article: http://blog.csdn.net/notonlyforshe/article/details/7955323

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.