I have an children's app with a large number of ImageButtons, each ImageButton displays a different, randomly-chosen animal image. When the app says, "Which one is the Monkey?" the child hopefully pushes the ImageButton with the monkey image.
To do this, however, I need code that can compare the image within the ImageButton to the target bitmap image in R.drawable. Previous posts here on StackOverflow have suggested that the solution to this problem is to set tags in the ImageButtons, but that is not a feasible solution here, for reasons too long to explain.
Here's my code thus far:
private boolean compareImages(ImageButton buttonPushed){
Drawable drawable = buttonPushed.getDrawable();
if(drawable.getConstantState().equals(R.drawable.monkey)) // NOT WORKING
return true;
return false;
}
In the debugger, I can see the equals() line fail, but I'm not sure why. I'm also not sure I'm comparing the same things, either. From reading up on other StackOverflow posts, it looks like the way to inspect the bitmap is with this:
Drawable drawable = buttonPushed.getDrawable();
drawable.getConstantState() <--- this points to R.drawable.monkey ???
Not sure. Anyone know the syntactic secret?