androidandroid-viewandroid-resourcesandroid-identifiers

How do I get the String representation of a View's id


I have a view and i have it's resource id ( i.e. R.id.xxx ) and i want to extract the xxx part and convert it to a String.

Is that possible to do?

Just to be clear, I have view.getId() a resource integer, not the actual name of the id.


Solution

  • View v;
    String ResourceIdAsString = v.getResources().getResourceName(v.getId());
    

    Use this in the view constructors