Android Custom CONTROLS: Reusable dialog pop-up box

Source: Internet
Author: User

Recently helped the studio to change a project, the demand is to produce many single-choice, multi-Select Dialog pop-up box, I feel a lot of code is reusable, wrote a reusable dialog class, not much to say, first look at the picture:




Due to some of the reasons for harmony, the actual effect is definitely better than this, here is basically a native property modification ... Let's talk a little bit about design ideas:


Why choose a custom dialog subclass instead of a alertdialog subclass (or something else)?


The dialog subclass is a parent class such as the Alertdialog subclass, which can be customized to a wider range (because of the sub-class attributes, methods, and so on, while having the necessary properties and methods), followed by the design of some sub-classes that make a person very painful. Take Alertdialog For example, Alertdialog's construction method is protected, which means that the Alertdialog class object and its subclass object cannot be obtained by means of new, but need to be obtained by getinstance. This makes it much more complicated to write custom controls and very painful. So based on the reduced trouble angle, I chose dialog to come from the definition.


What degree of optimization has been made?

First, I write most of the Findviewbyid methods in the class, or by passing in an array of resource files (Pickerdialog can have multiple selection boxes, in which case it is necessary to pass in an array to implement) to reduce the time spent in this step.


Second, although the requirements of the project vary, the controls used are mostly similar in nature. So I've added a constructor with the style parameter in my custom dialog, which means that people who use this custom dialog can spend less time tweaking a variety of UI details, as long as they're written in style.xml and can focus more on the code itself.


Finally, through the reflection mechanism to listen to the dialog within the click event, the user can only write the corresponding click event is OK.


Source in the bottom, everyone can download for free, I will not post it up


SOURCE download

Android Custom CONTROLS: Reusable dialog pop-up box

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.