我正在开发一个应用程序,其中我需要通过检查条件随机更改四个图像。它适用于四个不同的值(例如:2,4,1,3),但如果我对四个图像使用五个值(例如:2,3,3,1,4)。然后,我无法识别两次更改图像的区别。
我正在使用以下代码。
if(id==0 || id==4) //here 0,4 appears sequencially then
// blue image not changed two times.
{
light1.setImageResource(R.drawable.blue_on);
light2.setImageResource(R.drawable.red_off);
light3.setImageResource(R.drawable.green_off);
light4.setImageResource(R.drawable.yellow_off);
}
else if(id==1 || id==5)
{
light1.setImageResource(R.drawable.blue_off);
light2.setImageResource(R.drawable.red_on);
light3.setImageResource(R.drawable.green_off);
light4.setImageResource(R.drawable.yellow_off);
}
else if(id==2 || id==6)
{
light1.setImageResource(R.drawable.blue_off);
light2.setImageResource(R.drawable.red_off);
light3.setImageResource(R.drawable.green_on);
light4.setImageResource(R.drawable.yellow_off);
}
else if(id==3 || id==7)
{
light1.setImageResource(R.drawable.blue_off);
light2.setImageResource(R.drawable.red_off);
light3.setImageResource(R.drawable.green_off);
light4.setImageResource(R.drawable.yellow_on);
}