Why is the try block executed first, i want the colors to change first and then it should sleep fo 5000ms. i mean the system sleeps before the colors changes.
private OnClickListener CheckAnswer =new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
disableButtons();
Button incoming=(Button) arg0;
if(incoming.getText().toString().equals(Q.getAnswer()))
{
incoming.setBackgroundColor(Color.GREEN);
correct++;
score+=15;
}
else
{
incoming.setBackgroundColor(Color.RED);
wrong++;
if(C1.getText().toString().equals(Q.getAnswer()))
C1.setBackgroundColor(Color.GREEN);
else if(C2.getText().toString().equals(Q.getAnswer()))
C2.setBackgroundColor(Color.GREEN);
else if(C3.getText().toString().equals(Q.getAnswer()))
C3.setBackgroundColor(Color.GREEN);
modifyScore();
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
questionGenerator();
}
};`
I’d guess because the properties of the view are updated, but the screen redraw is stuck behind your sleep. DO NOT sleep on the main thread.
Instead create a Handler in the onCreate of your Activity and post a delayed Runnable to it.