比较ImageView的对象 [英] Compare ImageView Objects

查看:213
本文介绍了比较ImageView的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过自己的形象资源(封面图片被按钮使用)或图像资源的文件路径来比较两个ImageView的对象,无论是。

I need to compare two ImageView objects either by their image resource (the cover image being used on the button) or the filepath of the image resource.

线沿线的东西:

final ImageView button01 = (ImageView) findViewById(R.id.button01);
final ImageView button02 = (ImageView) findViewById(R.id.button02);
button01.setImageResource(R.drawable.myDogsPhoto);
button02.setImageResource(R.drawable.myDogsPhoto);
if (button01.getImageResource() == button02.getImageResource()) {
return true;
}

有人可以告诉我怎么可以去比较两个ImageView的成分?

Can someone please tell me how I can go about comparing two ImageView components?

感谢

推荐答案

一个可能的方法是使用的 View.setTag(); 方法来存储资源的价值(或文件路径字符串)。该setTag()和getTag()方法允许你任意数据附加到视图对象,您可以在以后召回任何你需要的目的。

One potential way is to use the View.setTag(); method to store the resource value (or filepath string). The setTag() and getTag() methods allow you to attach arbitrary data to the View object that you can recall later for whatever purpose you need.

例如:

final ImageView button01 = (ImageView) findViewById(R.id.button01);
final ImageView button02 = (ImageView) findViewById(R.id.button02);

button01.setImageResource(R.drawable.myDogsPhoto);
button01.setTag(R.drawable.myDogsPhoto);
button02.setImageResource(R.drawable.myDogsPhoto);
button02.setTag(R.drawable.myDogsPhoto);
if (button01.getTag().equals(button02.getTag())) {
    return true;
}

请注意我没有编译此,它可能需要你做出Integer对象传递给setTag()。

Note I didn't compile this, it might want you to make Integer objects to pass to setTag().

此外,我不知道这是否是去了解你想要做什么是最好的方式,但它是浮现在脑海的第一个。

Also I don't know if this is the best way to go about what you are wanting to do but it is the first that came to mind.

这篇关于比较ImageView的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆