How to get Resource Name from Resource id

Solution 1:

In your Activity, try these:

  1. to get string like radio1:

    getResources().getResourceEntryName(int resid);
    
  2. to get string like com.sample.app:id/radio1:

    getResources().getResourceName(int resid);
    

In Kotlin Now :

val name = v.context.resources.getResourceEntryName(v.id)

Solution 2:

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%.

Solution 3:

Kotlin:

val name = v.context.resources.getResourceEntryName(v.id)

Solution 4:

If I am right, what you wanted to retrieve is the word "radio1" (from the id itself?) so if that's the case then first you need to get its id.

int intname= buttonname.getId();

then get the result of it

String stringname= getResources().getResourceEntryName(intname);

hoped I helped