Android-widget Source Code Analysis

Source: Internet
Author: User



View and how all controls are aware of the control ID that we set in the layout.

"Attrs.xml file"

# attrs.xml file. <declare-styleable name= "View" > <!--reference represents a resource file!! --<attr name= "id" format= "reference"/> ... (n more info ha, see Code yourself) </declare-styleable>

"The initialization of the View"

 public static final int no_id = -1;  ... ... @ Viewdebug.exportedproperty (resolveid = true)  //  (note)  android-19/android/view/ viewdebug.java int mid = no_id; //  Save control ID, default value -1. ... ...      public view (context context, attributeset attrs, int  DEFSTYLEATTR)  {        this (context);         //  get view.         in the Attrs.xml properties file Typedarray a = context.obtainstyledattributes (                    attrs,  com.android.internal.r.styleable.view, defstyleattr, 0);        &NBSP;...&NBSP;...&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;...&NBSP, ..... (N Multiple codes,Omitted!)         for  (int i = 0; i < n;  i++)  {            int attr =  a.getindex (i);            switch  (attr)  {                  ...  .. (n multiple code, omitted!!)                 case  com.android.internal.r.styleable.view_id: //  the control ID to get the field in the View id.                     mID =  A.getresourceid (attr, no_id);                     break;


"Set control ID"

Sets the control ID.        public void setId (int id) {MID = ID;        if (Mid = = view.no_id && Mlabelforid! = view.no_id) {mid = Generateviewid (); }    }


"Get control ID"

Gets the control ID.    @ViewDebug. Capturedviewproperty public int getId () {return mID; }

Fff


Fff


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.