‫Welcome back.
‫We succeeded in getting and displaying the first question.
‫Now we need to display the other questions and the next questions when the user clicks on the next button.
‫By the way, where is the next button?
‫This is a layout issue.
‫I need to configure this text view and make the layout margin to 100.
‫Run it again and you can see the next button appears.
‫I need to add some margins here to that.
‫The to this text view.
‫And I'll add eight margin left and margin right eight run.
‫And here we go.
‫Now let's move to the main activity and create a new method called display.
‫All or next questions here I need to trigger this function when the user clicks on the next button.
‫So binding dot next button next dot set on click listener new view on click listener use display next
‫question inside this display.
‫Next question here I'll direct check the user if he finishes the questions and the quiz.
‫So I'm going to direct him to the results activity I'll configure this later on.
‫Now let's focus on displaying the question and getting the correct option.
‫I need to use a selected option integer value to check the selected option.
‫If it is not equal to minus one and it's not null.
‫Okay.
‫Binding dot radio group dot get checked radio button ID here I'm getting from the four radio buttons
‫the ID of the selected option.
‫I'm checking if this selected option doesn't equal minus one, so the user makes a selection radio button.
‫Radio button equals to find the view by ID, because I'm going to use this to detect the selected option
‫I'm casting it to this selected option.
‫Now if there is a next question then we need to do an if condition.
‫So if question list dot size minus I which is the the current question greater than zero.
‫What we need to do.
‫We need to get the total number of questions and check if the chosen option is correct.
‫Here I need to start with the getting number of questions.
‫So total questions equal to questions list dot size method.
‫This is very simple.
‫I use an array list question list and getting the size of it.
‫Then I'm getting to check if the chosen option is correct.
‫If radio button dot get text dot to string equals to.
‫Here I'm checking questions list dot get at index I dot get correct option if it is correct.
‫If the user chooses the correct option, I need to increase the result variable by one and set the text
‫this text to correct to correct answer binding dot text question or text result dot set text to correct
‫answer and the correct answers okay, this is if the chosen option is correct, so the user selects
‫the correct answer.
‫If I equals to zero, then I plus plus.
‫If it is the first question, increase I by one.
‫Now I need to display the next question.
‫So binding dot text question dot set text to question number I get the number by I plus one.
‫And here I need to use the question list dot get I not zero.
‫If we go back to the display first question we did it by getting the first index which is zero.
‫Here I'm getting the index I.
‫So I refers to the question index dot get question.
‫Then I need to update the radio buttons, the four radio buttons and display the four options.
‫So radio one dot set text to questions list dot get I dot get option one and also similar to the next
‫options.
‫And I want from you to focus with me and think like me.
‫We need to check if it is the last question, so we need to change that button from next to finish.
‫So if I which refers to the question index question list dot size and comparing it with the size of
‫the array list that contains the questions.
‫So if the index of the question equals to the question list dot size minus one, this is the last question
‫in the array list.
‫I'm going to use binding dot button.
‫Next dot set text.
‫To finish.
‫Here I'm changing the button title from next to finish.
‫Then I'm going to use binding dot radio group dot clear check.
‫Because I'm going to move to another question.
‫I need to clear the selection of the previous one and increase the I index, which is the question index
‫by one.
‫This is in the if close.
‫This is the if selected option is not null.
‫Else we need to check or display a toast message telling the user to make a selection.
‫So if the user didn't select any option and it clicks on the next button, I need to display a toast
‫message telling him that you need to make a selection.
‫Here.
‫I need to check also and use else condition.
‫And here this else is for this.
‫More questions to display.
‫I scroll down and remove this else and paste it here.
‫Then if radio button dot get text dot to string equals to question list dot get I minus one dot get
‫correct option.
‫Then we need to display the text text result dot set text to correct answer and we display the result
‫variable.
‫Also, I need to increase result by one.
‫Let's run and test our next button.
‫This is question number one.
‫Select 30 next.
‫So the correct answer is one.
‫Question number two what is the result of nine times nine.
‫And congratulation.
‫This is the second question.
‫So we are fetching all the questions here.
‫What is the result of nine times nine for example 80 to finish.
‫You can see finish is displayed and not next.
‫In the next videos we're going to direct the user to the results activity.