if (buttonClicked.contains(1) && buttonClicked.contains(2)) {
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
if (buttonClicked.contains(3) && buttonClicked.contains(4) && buttonClicked.contains(5)) {
if (playerOneLastClicked) {
imgViewBackground2.setImageResource(R.drawable.rca)
} else {
imgViewBackground4.setImageResource(R.drawable.wac)
}
}
player1 或 player2 上次单击(buttonClicked.contains(1) && buttonClicked.contains(2)) imgViewBackgound1
时发生更改,但是当玩家单击按钮3,4或5 imgViewBackground
时保持更改。< / p>
我希望imgViewBackground1
取(R.drawable.rca)
或(R.drawable.wac)
时不再更改。
答案 0 :(得分:0)
如果imgViewBackground
不会显示图片,则可以添加一个额外的支票,例如
if (imgViewBackground1.drawable == null) {
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
}
或者如果它已经有图像视图并且您不想再次设置它
if (imgViewBackground1.drawable != resources.getDrawable(R.drawable.rcs, null)
|| imgViewBackground1.drawable != resources.getDrawable(R.drawable.wac, null))
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
}