For me
In Question class
private int mAlreadyAnswer = 0;
public int getAlreadyAnswer() {
return mAlreadyAnswer;
}
public void setAlreadyAnswer(int alreadyAnswer) {
mAlreadyAnswer = alreadyAnswer;
}
and in MainActivity
private void checkAnswer(boolean userPressedTrue){
boolean answerIsTrue = mQuestionBank[mCurrentIndex].isAnswerTrue();
int answer = mQuestionBank[mCurrentIndex].getAlreadyAnswer();
int messageResId = 0;
if (userPressedTrue == answerIsTrue & answer == 0) {
messageResId = R.string.correct_toast;
mQuestionBank[mCurrentIndex].setAlreadyAnswer(1);
} else if (userPressedTrue != answerIsTrue & answer == 0) {
messageResId = R.string.incorrect_toast;
mQuestionBank[mCurrentIndex].setAlreadyAnswer(1);
} else {
messageResId = R.string.alreadyAnswer;
}
Toast toast1 = Toast.makeText(this, messageResId, Toast.LENGTH_SHORT);
toast1.setGravity(Gravity.TOP, 0, 0);
toast1.show();
}
in @String
<string name=“alreadyAnswer”>You are already answer this question</string>