In this one I created a list in MainActivity
//questions they cheated on
var cheatedList = mutableListOf<Int>()
and added the index of the cheated questions to it from the clicklistener of the CheatActivity
showAnswerButton.setOnClickListener {
val answerText = when{
answerIsTrue -> R.string.true_button
else -> R.string.false_button
}
answerTextView.setText(answerText)
//create a function to return the result to MainActivity
setAnswerShownResult(true)
cheaterStatus = true
cheatedList.add(currentIndex)
}
then in the checkAnswer function, i checked if the list contains the current index, if so display the judgment message
private fun checkAnswer(userAnswer : Boolean) {
val correctAnswer = quizViewModel.questionBank[quizViewModel.currentIndex].answer
val messageResId = if (cheatedList.contains(quizViewModel.currentIndex)) {
R.string.judgment_toast
} else if (userAnswer == correctAnswer) {
if (::answersMap.isInitialized) {
answersMap.put(quizViewModel.currentIndex, true)
} else {
answersMap = mutableMapOf(quizViewModel.currentIndex to true)
}
R.string.correct_toast
} else {
if (::answersMap.isInitialized) {
answersMap.put(quizViewModel.currentIndex, false)
} else {
answersMap = mutableMapOf(quizViewModel.currentIndex to false)
}
R.string.false_toast
}
Toast.makeText(this, messageResId, Toast.LENGTH_SHORT).show()
}
there you go…