Use Findviewbyme to improve component lookup efficiency in Android

Source: Internet
Author: User

1. Elicit

Androu scholars generally write Android activity in the OnCreate method will always add Setcontentview method to load layout, through the Findviewbyid to implement the binding of the control, In the beginning of the layout of the demo only one or two components OK, but suddenly contact a layout need to deploy a large number of controls, it will be very slow, fortunately androidstudio for everyone to provide a convenient plug-in Findviewbyme (you can also go to understand the annotations, Especially compile-time annotations that don't affect performance.

2. Operation Demonstrationin this demo, I have installed the plugin in advance, you can install it yourself, and then restart Androidstudio. 3. Precautions

(1) Add Rootview

For fragment need to add Rootview this, first tick "add Rootview";

Then enter the name of the Rootview in the edit box, example Contentview;

Finally click Add, the generated code is updated.

(2) the Viewholder in adapter

Tick "is Viewholder" on the line, the code is updated;

The control variable here no longer adds any modifiers.

Some variables have to be handled on their own, which is not mentioned here.

(3) Naming rules

Control variable naming rules: Variable naming is based on the control's ID, for example, the ID is edit_user_name, then the generated variable name is editusername;

Control variables use the private modifier by default;

on the question of adding "M", this simply tick "add" M "in the Redemption box, and the variable name becomes Meditusername.

4. Supplement

can also use Https://github.com/boredream/BorePlugin (more refreshing AH)

Code generation rules:

(1) Automatic traversal of all files with ID in the target layout, no recognition processing without ID

(2) The variable name generated by the control defaults to the ID name and can be modified by itself in the name entry field on the right side of the popup confirmation box.

(3) All buttons or controls with Clickable=true automatically generate Setonclicklistener-related code in the code

(4) All EditText control, will generate a non-null judgment code in the code, if the empty will prompt edittext hint content, if the hint is empty prompt xxx string cannot be empty word, finally will all input box verification merge into a Submit method

(5) The include tag in the layout is automatically recognized and the controls in the corresponding layout are read

Use Findviewbyme to improve component lookup efficiency in Android

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.