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