Android: how to get the name of a graphic image

I want to get the name of the image to be extracted, and I want to keep that name in a string. For example, for an image, I could use a .png file called play.png or stop.png. I just want to know which image in drawable is used for ImageView. Is there any way to get the name drawable / (??. Png)

Thank.

+5
source share
2 answers

I don’t think there is a direct way to get the name of the image to be drawn if you do not save the image name with the image.

In XML, you can do the following to set the image name as additional data for viewing images

android:tag="btful.png"

imagename

ImageView img = (ImageView) findViewByID(R.id.img)// my image
img.settag("btful.png"); // to set an image name

, getTag()

String imageName = (String)img.getTag();
+6

"drawableImgId", :

img.getId();

, img id ,

+1

All Articles