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.
Something along the lines of:
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;
}
Can someone please tell me how I can go about comparing two ImageView components?
Thanks
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.
For example:
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.