gpt4 book ai didi

android - 比较 ImageView 对象

转载 作者:行者123 更新时间:2023-11-29 18:11:27 25 4
gpt4 key购买 nike

我需要通过图像资源(按钮上使用的封面图像)或图像资源的文件路径来比较两个 ImageView 对象。

类似的东西:

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 组件?

谢谢

最佳答案

比较两个 ImageView 对象::

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

Drawable d=button01 .getDrawable();
Drawable d1=button02 .getDrawable();
if( d== d1){
Toast.makeText(Example.this, "hello", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(Example.this, "hai", Toast.LENGTH_SHORT).show();
}

关于android - 比较 ImageView 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10441451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com