Reputation: 23000
When you create a layout, you define an id for your views like this:
<ImageView
android:id="@+id/myImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/main01" />
and in your code you have:
ImageView img = (ImageView) findViewById(R.id.myImage);
now you have the object of img
.
How can I get the id of img
("myImage") as a string? I need something like this:
String strId = getStringId(img);
// now strId is "myImage"
Upvotes: 0
Views: 65
Reputation: 56925
Try this.
Log.i("============ Id","::"+getResources().getResourceEntryName(img.getId()));
Output : ============ Id :: myImage
Upvotes: 2
Reputation: 1034
Is this what you're looking for?
String value = getResources().getString(R.id.myImage);
Upvotes: 0