mercredi 25 octobre 2017

Quiz - Indicate incorrect/correct answers with colors

I am struggling with my little quiz app in Android Studio. I would like to indicate the correct answer with a blinking green button after I pressed the wrong Button. I randomized the answers on the Button on each try so I need to find a way to find the correct Text on the particular correct Button. My code so far:

//Check Answer:

public void checkAnswer(View view) { 
    // Get clicked button.
    final Button answerBtn = (Button) findViewById(view.getId());
    String btnText = answerBtn.getText().toString();

     if (btnText.equals(rightAnswer)) {
        // Correct Answer.
        timer.cancel();
        rightAnswerCount++;
        soundPlayer.playCorrectSound();
        answerBtn.setBackgroundColor(Color.parseColor("#3fd250"));

    } else {
        // Wrong Answer.
        timer.cancel();
        soundPlayer.playWrongSound();
        answerBtn.setBackgroundColor(Color.parseColor("#da251c")); 
        quizLife--;

    }

Aucun commentaire:

Enregistrer un commentaire