Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve EditText's xml id

I have a form with many EditTexts, and when I press a certain button, I need to retrieve all these controls and put them into a HashMap so the key is the name (key1 int the following code)

<EditText android:id="@+id/key1" 
        style="@style/keys" /> 

and the value, whatever text the user enters.

My question is, how can I retrieve the name of the EditText for the Hashmap's keys ? getId() returns a number.

Thanks

like image 573
xain Avatar asked Jan 31 '11 14:01

xain


2 Answers

Android generates a handle for that View in R.java whenever you build your project. For instance, once you build you can access your EditText by calling R.id.key1. You don't have to store the ids anywhere because you can access the id directly at any time in your code. With this id you can call findViewById() as dave.c mentions to get whatever view you need from your XML.

like image 106
McStretch Avatar answered Oct 05 '22 09:10

McStretch


I finally solved it using android:tag and getTag()

like image 44
xain Avatar answered Oct 05 '22 09:10

xain