Welcome back in this video, we are going to be able to select the answers and submit them so that they
will change to color accordingly, if we were right, then it will be Turn Gruden's on, for example,
selected Argentina, so it turns green.
But if I so well, select the wrong answers.
So here, for example, I select Angola, it's going to show me the wrong answer in red and the correct
answer in green.
OK, so let's set this up.
And also you can see that the submit button changes to go to next question as well as we go to the next
question.
Once we click on that.
All right, so let's get started.
Therefore, the first thing that I will need to do is to duplicate this default option border.
So I'm going to copy and paste and this one will be the correct option.
Border BCBG and what it will be different with is it's not going to have a stroke, but instead it's
going to have a another color as the background here.
And I'm going to use Holo Green Light.
Like so.
And if that doesn't exist in your case, you need to add Android Colin color.
So let me see.
It's an underscore light.
Like so so this whole green light, that's the color that I want to use if I have selected the correct
answer.
You see, with only the stroke surrounding it and now let me copy and paste this once again and this
one will be the wrong option.
Border and outlets designed this wrong option border here.
I just would like to use, although red light, which will be this red color.
OK, so now we have the wrong option border here and the correct option border, which had trouble.
So there just well, basically images, so to speak, that we can now use in our project.
So the idea is that our possible options should be colored accordingly if we answered them correctly
or incorrectly.
And in order to find out what was selected or assigned a color, let's just say this way, I'm going
to create a new variable, which I'm going to call answer, review and it needs to know the answer.
And it needs to know the tribal view and to draw a view, while you might think it's an image or something
like that, it's just going to be the integer, which is just, uh.
Well, the location of the trouble, so to speak.
Each of them has an idea and it's an integer, so we can just assign it this way so we can check the
answer and we can use a Winklevoss here because it's an integer.
And if the answer is one, what I'm going to do is I'm going to set the option one background.
To be fair, draw view color.
So whatever the job of you is that I want to assign whether it's red or blue or green, I'm going to
just assign that.
And we can just use the context compared once again with the get to draw bill, which will then give
me the trouble.
I need, however, to pass in the context as well as the integers that a view that I want to assign
so get rubble.
This method it requires, as you can see here, a national context as well as an integer, which is
the Trouble Resources ID. And that's exactly what I'm passing here.
Now we need to do the same thing with the other options.
So I'm just going to copy them in here.
And the only difference is really that there's no Option two that we are assigning this to.
Then we have option three for the number three and option four for the number for accordingly.
So depending on what the answer is, so if the answer is one or the answer is two or the answer is three
and so forth.
OK, so that's the answer that the user selected and the color that we're going to assign depends on
whether we were right or wrong.
So let's assign the code for that.
Therefore, once we click on the submit button, what I want to do is I want to check if the selected
option.
So the selected option position is zero because that's what it is by default.
And then I'm going to increase the current position by one, which means I'm going to go to the next
question, so to speak.
So I'm selection option position equals equals zero.
Let's see why I'm using zero.
Well, that's because zero is the selected option by default.
So I just set this value to zero, and whenever we select an answer, it will be overriding the value
there.
OK.
So that's our current position.
And what I'm going to do is as long as I have questions left, I'm going to ask the next question.
So here I am.
Current position less or equal, I'm questions list size.
So that size in that case, let me set the question.
So it's just going to call this question method that we have created earlier where we set the new image,
where we set the question, as well as the possible options.
OK, so now.
This is when we submit and selected option position was set to zero.
Otherwise, what I want to do is I want to get the question.
So here I am questions list and I need that because I need to know at which position we are and what
the correct answer is.
So, and current position minus one.
And this will just give me the question that fits to the current question that I'm at because the current
position is going to be, you see here increased by one and it's going to be one by default.
And because an ArrayList starts counting at zero.
So this question's list starts counting at zero and has its indexes.
We just need to add this minus one.
So now.
We can check if the question.
Correct answer.
It's going to be the same or not the same, so selected options position.
And here are some questions, but the question and because question is a Nullarbor as it contains a
Nullarbor as its answer, we need to use the double question marks or we assigned another bill to it,
which now means it's another bill itself as well, which if you want to use it, you need to force unwrap
it.
So here we can now.
Or you can, of course, use the your light and so forth.
But I'm not going to go into debt to make it even more complicated in this case.
So here we can call the answer view.
Now we can pass in the selected option that we selected as the user and can pass into the image that
we want to use.
So what I'm going to use is the wrong option.
Border background So if the answer was incorrect, I'm going to select that and display the red background
and otherwise or in general.
So let me.
Get those curly brackets here, and in general, what I'm going to do is I'm going to colored the correct
answer.
Print, so here, question that correct answer should be art dot, drobo dot.
Correct option border background.
OK, so that's what this.
The thing you will do for me, let's run this.
Let's see if this is going to do the trick for us.
So here, submit you see Argentina was correct, so it shows me the correct color and that was stupid
of me to select the right answer.
I was stupid of me.
Now let's select Australia and you see the wrong one.
Got the red colour and the right one got the green color.
So no matter if we are wrong or right, the right color will always be turning green, so it will always
get this correct option.
Border background.
So now I also want to check if I'm at the end of my questions and want to jump to the next question.
So let me click submit.
You see, we don't get to the next question.
So let's get to the next question.
And therefore, I'm going to first check if the current position and here and details to a global variable
is equal to the amount of questions that I have.
And if that's the case, I'm going to set the button.
Submit text, how do they call this button?
I think I called it beat and submit.
So he had BTN submit.
Yeah, I'm going to set that text to finish.
And otherwise, I'm going to set it to be.
Go to next question.
So here, button submit the text will be go to next question and this was button submit.
So in my case?
And what's really important is no matter what I need to set back the selected option position to zero
because otherwise we will always stay at the current selected option and we will get areas where the
app will not behave as we wanted to.
OK, so now let's go ahead and test this.
Let's go here, let's of the wrong one that seems to work, the tax changes to go to next question.
And now you see, oh, that doesn't seem to have reset.
So the colors have not reset, but at least we are on the next question, which is great.
OK, so you see, the progress bar has changed the progress bar text view as well as the image has changed.
While the question, technically speaking, also has changed, even though it's the exact same same
question, but yeah, every option has changed.
So all of that seems to work flawlessly, except for the resetting of the colors.
And now where would be a good spot to reset the questions?
Well, option colors to reset them to our default where this method called default options view, which
we had set up this one here, where would be a good spot to call it?
Well, I'd say at the moment where we set the question.
So here we can just go ahead and call this method where we reset all of the options to be great again.
So let's run that real quick.
And let's under a name.
Let's select Armenia, even though it's incorrect, go to next question.
You can see now it's reset.
OK, so now let's just go to the end and we have multiple problems.
Still, you can see we can submit even without selecting something.
And then once we are at the end, we click on finish and nothing happens.
So what I want to do for now is I want to let the user know that they made it to the end of the quiz.
So I believe that would be here when we don't have any more questions.
So here else or not else, but we're in a one class, so we need to do it slightly differently here.
And then else, like so because we are in a weight class, so we're using the lambda expression here.
And what I'm going to say for now, it's just going to be a toast.
OK, so toast, make text and you see here I need to pass in the context and say what I want to display.
Uh, congrats.
You've made it.
Yeah, made it to the end.
Okay.
All right.
Let's try this once again.
And make it to the end to solve some in some and some bits and submit.
And you made it to the end.
So of course, we want to send the user down to a results screen where you can then see how many questions
he has correct and so forth.
But for now, that will do the trick.
And by the way, this I wrote, what is problem with just clicking on submit, submit, submit to something
we're not going to change for now because maybe the user doesn't know and he just wants to submit and
he doesn't even want to select something.
OK, so that's it for this video.
See you in the next one where we are going to prepare the UI for the result activity or actually we
need to look at how to start activity for result works first.
So let's see there.