Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Text Colors not changing
    text
    copied!<p>I'm writing a quiz application which presents the user with a question and 4 choices. When the user clicks on a choice, the app should change the colour of the correct choice to green and the colour of the incorrect choice to red. It should then wait a second before displaying the next question.</p> <p>The problem is that it doesn't do the colour changes (except for the last question) and I don't understand why. I know that my <code>android.os.SystemClock.sleep(1000)</code> has something to do with it. </p> <p>I'd appreciate it if you could tell me where I've gone wrong or if I'm going about this an incorrect way. Thanks :)</p> <pre><code>public void onClick(View v) { setButtonsEnabled(false); int answer = Integer.parseInt(v.getTag().toString()); int correct = question.getCorrectAnswer(); if(answer == correct) numCorrect++; highlightAnswer(answer,correct,false); android.os.SystemClock.sleep(1000); MCQuestion next = getRandomQuestion(); if(next != null) { question = next; highlightAnswer(answer,correct,true); displayQuestion(); setButtonsEnabled(true); } else { float percentage = 100*(numCorrect/questionsList.size()); QuizTimeApplication.setScore(percentage); Intent scoreIntent = new Intent(QuestionActivity.this,ScoreActivity.class); startActivity(scoreIntent); } } private void setButtonsEnabled(boolean enable) { for(Button b: buttons) b.setEnabled(enable); } private void highlightAnswer(int answer, int correct, boolean undo) { if(undo) { for(Button button : buttons) { button.setTextColor(getResources().getColor(R.color.white)); button.setTextSize(FONT_SIZE_NORMAL); } return; } buttons[correct].setTextColor(getResources().getColor(R.color.green)); buttons[correct].setTextSize(FONT_SIZE_BIG); if(answer!=correct) { buttons[answer].setTextColor(getResources().getColor(R.color.red)); buttons[answer].setTextSize(FONT_SIZE_BIG); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload