我目前正在构建一个在主视图上有 6 张图像的应用程序,它会从我的drawable
文件夹中生成随机图像(洗牌)
初始化卡组:
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));
}
洗牌:
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;
}
在我的主要活动中,我将卡片分配给视图,当用户点击它们时,我想知道图像是一张特技卡片还是一张普通卡片。
有没有办法找出被点击的卡片是否是一个技巧?像if(image.getImageDrawable().equals(R.drawable.trick.jpg)
什么?