pro_2911
pro_2911

Reputation: 163

Comparing the id of two views in android?

I have 2 image buttons in my Android project. I have set some images for the buttons and I change those images in the program. I want to check if the two image buttons have the same images, how can I check that??

I tried directly comparing them in an if statement by getting the two ids using getId(), but my program stops responding...

Upvotes: 0

Views: 1527

Answers (1)

gaurav5430
gaurav5430

Reputation: 13892

you can try to check the Source of the ImageView, if it is same. you can not do it directly, as there is no method provided by default. but you can try something like this using Tag

in onCreate():

imageView0 = (ImageView) findViewById(R.id.imageView0);
imageView1 = (ImageView) findViewById(R.id.imageView1);

imageView0.setTag(R.drawable.one);
imageView1.setTag(R.drawable.two);

//you can create a simple function to get the drawable id:
private int getDrawableId(ImageView iv) {
    return (Integer) iv.getTag();
}

this is assuming that same images are picked up from same location. if you have same images being picked up from different locations, then you want to compare Bitmaps.

Upvotes: 2

Related Questions