2
\$\begingroup\$

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:

enter image description here

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

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ 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! \$\endgroup\$ – NullPointerException Nov 29 '15 at 1:03
  • \$\begingroup\$ 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? \$\endgroup\$ – NullPointerException Nov 29 '15 at 1:05
  • \$\begingroup\$ 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 \$\endgroup\$ – NullPointerException Nov 29 '15 at 1:13
  • \$\begingroup\$ 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. \$\endgroup\$ – NullPointerException Nov 29 '15 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.