Created
February 8, 2020 22:32
-
-
Save Elijah-Dangerfield/cb7738a5600bf48962528252d2a2c213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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