Skip to content

Instantly share code, notes, and snippets.

@Elijah-Dangerfield
Created February 8, 2020 22:32
Show Gist options
  • Save Elijah-Dangerfield/cb7738a5600bf48962528252d2a2c213 to your computer and use it in GitHub Desktop.
Save Elijah-Dangerfield/cb7738a5600bf48962528252d2a2c213 to your computer and use it in GitHub Desktop.
var questionList: List<Question>? = null
private fun observeQuestions() {
questionsViewModel.getQuestions().observe(viewLifecycleOwner, Observer {
//this code runs every time the data changes.
questionList = it
getNextQuestion()
})
}
private fun handleNext(){
getNextQuestion()
radioGroup.clearCheck()
tv_wrong.visibility = View.INVISIBLE
tv_correct.visibility = View.INVISIBLE
questionsViewModel.setAnsweredState(AnsweredState.Answering)
}
private fun getNextQuestion() {
if(questionsViewModel.currentQuestionIndex >= questionList?.size ?: 0) {
questionsViewModel.currentQuestionIndex = 0
}
currentQuestion = questionList?.get(questionsViewModel.currentQuestionIndex++) ?: return
updateQuestion()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment