-1

In Android there is this method to get the id of a view:

int id = view.getId();

But this returns a dynamically generated integer value that has been assigned to the view at runtime.

I need to access the original string id. For example, for the following view, I want to get @+id/likesCount:

<TextView
  android:id="@+id/likesCount"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />

How can I get that?

  • 3
    The most happy duplicate of my entire lifetime. I never knew that I had to search for resources. I was searching for string id in android and I could get no results. Thank you. – mohammad rostami siahgeli Jul 16 '18 at 05:22

1 Answers1

0

You can not, the right approach to do it is using tag. You can give that id in tag and programmatically get it.

String id = view.getTag().toString()
Ravi
  • 34,851
  • 21
  • 122
  • 183