Code_Life Code_Life - 3 months ago 12
Android Question

How to get Resource Name from Resource id



In my layout I have defined something like this .

<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dnt want this text" />


Assume that some function in activity returns me this id (id of radioButton). Now i want to get this text radio1 from this id.
In short I want to retrieve text radio1 written in
android:id="@+id/radio1"


Can somebody tell me how is it possible ?

Answer

In your Activity, try the following

getResources().getResourceEntryName(int resid);

or

getResources().getResourceName(int resid);

You'll prefer the first one I guess.

Comments