Get the ability to draw from ImageView

I am currently creating an application with 6 images in the main view and generating random images from my folder drawable(shuffling a deck of cards).

deck initialization:

public static void initDecks() {
    int m = 0;
    for (int i = 0; i < suites.length; i += 1) {
        for (int j = 0; j < regularCards.length; j += 1) {
            regularDeck[m++] = "drawablw/" + suites[i] + regularCards[j]
                    + ".jpg";
        }
    }
    m = 0;
    for (int i = 0; i < suites.length; i += 1) {
        for (int j = 0; j < trickCards.length; j += 1) {
            trickDeck[m++] = "drawable/" + suites[i] + trickCards[j]
                    + ".jpg";
        }
    }

    Collections.shuffle(Arrays.asList(regularDeck));
    Collections.shuffle(Arrays.asList(trickDeck));
}

shuffle the deck:

public static String[] getCards(int size) {
    String[] result = new String[size];
    for (int i = 0; i < size - 2; i += 1) {
        result[i] = regularDeck[i];
    }
    result[size - 1] = trickDeck[0];
    Collections.shuffle(Arrays.asList(result));
    return result;
}

in my main action, I assign cards to the view and when the user clicks on them, I want to know if the image is trick or ordinary.

Is there a way to find out if the card the trick was clicked on or not? something like if(image.getImageDrawable().equals(R.drawable.trick.jpg)?

+3
source share
3 answers

/ , ImageView. , - /, .

+1

,

drawable ImageView

ImageView, - ImageView , ....

0
public static Integer getDrawableId(ImageView obj)
    throws SecurityException, NoSuchFieldException,
    IllegalArgumentException, IllegalAccessException, ClassNotFoundException {
        Field f = ImageView.class.getDeclaredField("mResource");
        f.setAccessible(true);
        Object out = f.get(obj);
        return (Integer)out;
}

, Drawable mResource ImageView.

, Drawable ImageView . Drawable Uri. mResource reset 0. .

0

All Articles