java - What is id used for? -


this question has answer here:

<textview   android:id="@+id/button01"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:text="sample"   /> 

in code,

android:id="@+id/button01 

mean? , when use id?

as said in documentation

id

any view object may have integer id associated it, uniquely identify view within tree. when application compiled, id referenced integer, id typically assigned in layout xml file string, in id attribute. xml attribute common view objects (defined view class) , use often. syntax id, inside xml tag is:

android:id="@+id/my_button" 

the at-symbol (@) @ beginning of string indicates xml parser should parse , expand rest of id string , identify id resource. plus-symbol (+) means new resource name must created , added our resources (in r.java file). there number of other id resources offered android framework.

example in same doc :

<button android:id="@+id/my_button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/my_button_text"/> 

now can uniquely identify button

button mybutton = (button) findviewbyid(r.id.my_button); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -