How to get the drawable name from my image in a list view Android

半腔热情 提交于 2019-12-13 06:26:01

问题


Ok so I have a list view with a custom list view adapter, and each list item has an "icon". when I click the list item, I am easily able to get all the text field names such as name address etc. I have their icon in an image view (obviously every icon is in the same id because it is getting reused in the listview). my question is how can i get the r.drawable.resource (ie pic1) when i click the list item . and pass it to my next intent (I know how to use bundle extras).

I have been searching and I can set the resource but cannot retrieve it from a imageview. Passing the Image in PutExtra in Android

most answers I have seen are like the link above, and this assumes that you either have different ids for each image view or that you want to turn the image view into bytes(do not want to do that). does anyone know how to get the r.drawable from the image view?

ImageView myimage = (ImageView) view.findViewById(R.id.myrate);

回答1:


When you set the imageView's drawable, you can set the ImageView's tag:

imageView.setTag(R.drawable.my_drawable);
imageView.setDrawableResource(R.drawable.my_drawable);

And later use:

imageView.getTag();


来源:https://stackoverflow.com/questions/17393508/how-to-get-the-drawable-name-from-my-image-in-a-list-view-android

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