Answers for "private void checkAnswer(boolean userPressedTrue) { ... mQuestionsAnswered[mCurrentIndex] = true; mTrueButton.setEnabled(false); mFalseButton.setEnabled(false); ... }"

0

private void checkAnswer(boolean userPressedTrue) { ... mQuestionsAnswered[mCurrentIndex] = true; mTrueButton.setEnabled(false); mFalseButton.setEnabled(false); ... }

if (savedInstanceState != null) {
        // Save Current Index of question
        mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);
        // Save whether question has been answered.  Do not let user answer again.
        int[] mQuestionAnswerArray = savedInstanceState.getIntArray(QUESTION_LIST);
        for (int i=0; i<mQuestionBank.length; i++)         {
            mQuestionBank[i].setAnswered(mQuestionAnswerArray[i]);
        }
    }



@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    Log.i(TAG, "onSaveInstnaceState");
    savedInstanceState.putInt(KEY_INDEX, mCurrentIndex);
    int[] mQuestionAnswerArray = new int[mQuestionBank.length];
    for (int i=0; i<mQuestionBank.length; i++)         {
        mQuestionAnswerArray[i] = mQuestionBank[i].isAnswered();
    }
    savedInstanceState.putIntArray(QUESTION_LIST, mQuestionAnswerArray);
}


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

private void setButtons() {
    if (mQuestionBank[mCurrentIndex].isAnswered() > 0) {
        // make buttons disabled
        mTrueButton.setEnabled(false);
        mFalseButton.setEnabled(false);
    } else {
        mTrueButton.setEnabled(true);
        mFalseButton.setEnabled(true);
    }
}

private void checkAnswer(boolean userPressedTrue) {
    boolean answerIsTrue = mQuestionBank[mCurrentIndex].isAnswerTrue();

    int messageResId = 0;

    if (userPressedTrue == answerIsTrue) {
        mQuestionBank[mCurrentIndex].setAnswered(2);
        messageResId = R.string.correct_toast;
    } else {
        mQuestionBank[mCurrentIndex].setAnswered(1);
        messageResId = R.string.incorrect_toast;
    }
    setButtons();
    Toast.makeText(this, messageResId, Toast.LENGTH_SHORT).show();
}
Posted by: Guest on March-03-2021

Code answers related to "private void checkAnswer(boolean userPressedTrue) { ... mQuestionsAnswered[mCurrentIndex] = true; mTrueButton.setEnabled(false); mFalseButton.setEnabled(false); ... }"

Browse Popular Code Answers by Language