vendredi 29 décembre 2017

How to pop up answers to the questions in android studio?

I want to display on the screen answers to each question in the quiz everytime I will press the true button.

So here is my snippet of code in java:

private Question[] mQuestionBank = new Question[]{
        new Question(R.string.volcano, true),
        new Question(R.string.drinking_milk, true),
        new Question(R.string.woman_oscar, true),
        new Question(R.string.hurricanes, true),
        new Question(R.string.pyramids_of_giza, true),
        new Question(R.string.coca_cola, true),
        new Question(R.string.sputnik, true),
        new Question(R.string.napoleon_bonaparte, false),
        new Question(R.string.brazil_soccer, true),
        new Question(R.string.barack_obama, false),
};
private int mCurrentIndex = 0;
private boolean[] mIsCheater = new boolean[mQuestionBank.length];

private void updateQuestion() {
    int question = mQuestionBank[mCurrentIndex].getTextResId();
    mQuestionTextView.setText(question);
}

private void checkAnswer(boolean userPressedTrue) {
    boolean answerIsTrue = mQuestionBank[mCurrentIndex].isAnswerTrue();
    int messageResId = 0;
    if (mIsCheater[mCurrentIndex]) {
        messageResId = R.string.judgment_toast;
    } else {
        if (userPressedTrue == answerIsTrue) {
            messageResId = R.string.correct_toast;
        } else {
            messageResId = R.string.incorrect_toast;
        }
    }
    Toast.makeText(this, messageResId, Toast.LENGTH_SHORT).show();
}

Thank you very much!

Aucun commentaire:

Enregistrer un commentaire