What is the co-relation between View\'s getId() method and the id defined in the XML file? Is there any? My IDs look like this: \"field1\", \"field2\"... This digits at the end
What is the co-relation between View's getId() method and the id defined in the XML file?
getId()
returns the android:id
value, or the value you set via setId()
.
My IDs look like this: "field1", "field2"
In your XML, they may look like @+id/field1
and @+id/field2
. Those are allocating ID resources, which are turned into numbers at compile time. These are the numbers you refer to in Java code as R.id.field1
and R.id.field2
.
This digits at the end are very important for my application and I need to retrieve them. Is there any way to do it?
Have a big switch statement comparing the ID to R.id.field1
, etc. Or, set up a HashMap
to map between the getId()
values and your "very important" numbers. Or, find some other solution that does not involve magic names on your ID values.