Comparing the images

I have a drawable, which I want to compare to. I created a drawable object with it, and when I log it with toString, I get:

android.graphics.drawable.BitmapDrawable@41f95548


I am randomly selecting a button, and I want to keep randomly selecting until the image of the image button is not android.graphics.drawable.BitmapDrawable@41f95548 Now, I want to compare using this code:

do{
}while(buttonBackground = android.graphics.drawable.BitmapDrawable@41f95548 ));


buttonBackground is a drawable object.

This, for some reason, gets me an error:

How can I compare images with a code like this android.graphics.drawable.BitmapDrawable@41f95548. What is this code called? Thanks

You could make it legal by saying

while(buttonBackground.toString().equals("android.graphics.drawable.BitmapDrawable@41f95548"))


That's apples-to-apples. But it probably won't be doing what you intend.

A better way will be to remember which index you chose, and then compare the index til you get a different one. Something like

int currentIndex = <something, the current button image>...

...
int newIndex = rng.nextInt(4)
} while(newIndex != currentIndex);


(By the way, Do you mean != or ==? Are you choosing randomly til you get a different one?)

Hope that helps a little!

• Hey, so for the index thing...I wish I could do that, but I cant. See, my program is getting a random button and then swapping the properties of the two buttons. I was doing the index thing here: gamedev.stackexchange.com/questions/112025/… But...it was too slow. I like your "apples to apples" method. Why did you mention it will probably not work? Thanks, I have liked, and will mark best answer once I get this! – NullPointerException Nov 29 '15 at 1:03
• Also...I meant ==. I wrote it wrong in my screen shot. I guess I should change it to .equals when trying your "apples to apples" method, right? – NullPointerException Nov 29 '15 at 1:05
• Hmm...I think I know why you were saying it wont work...That code is changing every time, which means it wont work some times? It is not constant. Why is that, isn't there only one image code? What is that code even called? Thanks so much – NullPointerException Nov 29 '15 at 1:13
• How should I compare the images now? I just don't want the image button that I pick from the array list to have that one image. – NullPointerException Nov 29 '15 at 1:14