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 ?
int resourceId = this. getResources(). getIdentifier("nameOfResource", "id", this.
drawable for all drawable resources) and for each resource of that type, there is a static integer (for example, R. drawable. icon ). This integer is the resource ID that you can use to retrieve your resource.
The unique identifier for an entity in the Google Ads API is called a resource name, and is represented as a string with a predictable format. If you know the constituent components of a resource name, you can generate resource names using helper methods present on many Service objects.
In your Activity, try these:
to get string like radio1
:
getResources().getResourceEntryName(int resid);
to get string like com.sample.app:id/radio1
:
getResources().getResourceName(int resid);
In Kotlin Now :
val name = v.context.resources.getResourceEntryName(v.id)
You have id('long' type) from that id you want to access radio button id(name) that is radio1. You use this
getResources().getResourceEntryName(id);
in using above you can get name of radio button i.e. radio1. here parameter id is which you have(long type). Try this it will helps you 100%.
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