开发者

How to check what photo is currently presented on the screen by ImageView (in android)?

A bit wierd problem:

Is it possible to get back id or/and a name of active resource in an ImageView? That's the code.

ImageView photo = (ImageView) findViewById(R.id.placeForPhoto);
//here I choose random photo from drawable (photo 1 to photo 10)
//and then I show it on the screen as below
photo.setImageResource(R.drawable.photo1); //or photo2 or photo3 or...

In the 开发者_Python百科other part of the code I would like to check which photo is atm presented in placeForPhoto. If it's R.drawable.photo1 or R.drawable.photo2 or...

So what I need is just smth like to have a possibility to achieve such a comparison:

if ([presented atm photo in ImagView photo] == R.drawable.photo1) 
{do something}
else if ([presented atm photo in ImagView photo] == R.drawable.photo2) 
{do smth different}
else {...}

I tried: photo.getID() but it returns ID of placeForPhoto not for the resource inside;

photo.getResource() but it returns some other value different than id of photo

getResource().getIdentifier() but it gives id when you have the name and I don't have the name (or maybe it's possible to get the name from ImageView photo?)

getResources().getResourceName() but then I have to have id which I'm just looking for.

Thx in advance.


Is it possible to get back id or/and a name of active resource in an ImageView?

No, because an ImageView does not have to hold a resource. It could hold a bitmap obtained by other means (e.g., download from the Web).

So what I need is just smth like to have a possibility to achieve such a comparison

Store the ID in a data member of the activity, or in the tag of the ImageView (i.e., setTag() and getTag()).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜