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
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.
I finally solved it using android:tag and getTag()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With