1

i have matrix of image button, i want to know which one was clicked by their image background. how i get the image button BackgroundResource?

like:

    switch (image.getBackgroundResource()) {
       case R.mipmap.blueflower
          image.setBackgroundResource(R.mipmap.cardback1);
          break;
       case R.mipmap.cardback1:
          image.setBackgroundResource(R.mipmap.blueflower);
          break;
       }

Thanks

Shay Zambrovski
  • 401
  • 5
  • 21
  • 2
    Don't know about that, but you can set `android:tag` on each of the buttons and differentiate them by tags. – Vucko Aug 06 '16 at 17:25
  • 1
    http://stackoverflow.com/questions/31651209/how-to-get-the-image-name-of-the-imageview-in-android – Sangeeta Aug 06 '16 at 17:28

1 Answers1

2

Toggling through setTag and getTag is one way to do it, probably the simplest.

There are a few ways to directly compare an image...

Can you get drawable? image.getDrawable(), then img1.equals(img2), (you might need a getConstantState() in there)

Bitmap? bmp1.sameAs(bmp2) or pixel by pixel Comparing Bitmap images in Android

Community
  • 1
  • 1
TWL
  • 6,228
  • 29
  • 65