Some expert tell me why this code doesn't work, the purpose is simple to change the color of a button for a certain period of time, after that period you must color returns to original color. The problem is that is not run in order, should be a button to change the color, wait 1s, back to original color then the same for the next button to complete the sequence.
Sorry my bad English and thanks in advance.
int temp[] = new int[game.getLevel()];
Handler handler = new Handler();
temp = game.getSequence();
for(int i = 0; i < game.getLevel(); i++)
{
switch (temp[i])
{
case RED:
handler.postDelayed(new Runnable() {
public void run() {
redButton.setBackgroundColor(Color.rgb(255, 0, 0));
}
}, 1000);
redButton.setBackgroundColor(Color.rgb(109, 0, 0));
break;
case GREEN:
handler.postDelayed(new Runnable() {
public void run() {
greenButton.setBackgroundColor(Color.rgb(0, 255, 0));
}
}, 1000);
greenButton.setBackgroundColor(Color.rgb(0, 109, 0));
break;
case YELLOW:
handler.postDelayed(new Runnable() {
public void run() {
yellowButton.setBackgroundColor(Color.rgb(255, 255, 0));
}
}, 1000);
yellowButton.setBackgroundColor(Color.rgb(109, 109, 0));
break;
case BLUE:
handler.postDelayed(new Runnable() {
public void run() {
blueButton.setBackgroundColor(Color.rgb(0, 0, 255));
}
}, 1000);
blueButton.setBackgroundColor(Color.rgb(0, 0, 255));
break;
default:
break;
}
}
}
0 comments:
Post a Comment