Why the Sleep executes first and than the code above it in android?
<p>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() {</p>

<pre><code>    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();
    }
};`
</code></pre>
