Android: How to get Drawable Image name

余生长醉 提交于 2019-11-28 01:59:16

I donot think there is any direct way to get name of drawable image unless you stores the image name along with image.

In XML you can do the following to set image name as an additional data to imageview

android:tag="btful.png"

Programmetically setting imagename

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

you can get the image name by using getTag()

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

Regarding your second question "drawableImgId"why not use:

img.getId();

I have multiple images and need to know which img id I am passing to other activities, it works for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!