1
00:00:00,750 --> 00:00:07,110
Welcome back in this video, we are going to be able to select the answers and submit them so that they

2
00:00:07,110 --> 00:00:11,310
will change to color accordingly, if we were right, then it will be Turn Gruden's on, for example,

3
00:00:11,730 --> 00:00:13,650
selected Argentina, so it turns green.

4
00:00:13,920 --> 00:00:16,770
But if I so well, select the wrong answers.

5
00:00:16,770 --> 00:00:23,130
So here, for example, I select Angola, it's going to show me the wrong answer in red and the correct

6
00:00:23,130 --> 00:00:24,120
answer in green.

7
00:00:24,480 --> 00:00:26,640
OK, so let's set this up.

8
00:00:26,640 --> 00:00:31,620
And also you can see that the submit button changes to go to next question as well as we go to the next

9
00:00:31,620 --> 00:00:32,159
question.

10
00:00:32,549 --> 00:00:33,900
Once we click on that.

11
00:00:34,470 --> 00:00:35,910
All right, so let's get started.

12
00:00:37,290 --> 00:00:41,970
Therefore, the first thing that I will need to do is to duplicate this default option border.

13
00:00:41,970 --> 00:00:48,720
So I'm going to copy and paste and this one will be the correct option.

14
00:00:48,780 --> 00:00:58,560
Border BCBG and what it will be different with is it's not going to have a stroke, but instead it's

15
00:00:58,560 --> 00:01:02,700
going to have a another color as the background here.

16
00:01:03,910 --> 00:01:07,750
And I'm going to use Holo Green Light.

17
00:01:08,770 --> 00:01:09,250
Like so.

18
00:01:09,550 --> 00:01:13,090
And if that doesn't exist in your case, you need to add Android Colin color.

19
00:01:14,140 --> 00:01:15,370
So let me see.

20
00:01:16,350 --> 00:01:18,300
It's an underscore light.

21
00:01:18,390 --> 00:01:23,850
Like so so this whole green light, that's the color that I want to use if I have selected the correct

22
00:01:23,850 --> 00:01:24,390
answer.

23
00:01:24,690 --> 00:01:30,660
You see, with only the stroke surrounding it and now let me copy and paste this once again and this

24
00:01:30,660 --> 00:01:33,150
one will be the wrong option.

25
00:01:33,150 --> 00:01:37,160
Border and outlets designed this wrong option border here.

26
00:01:37,170 --> 00:01:42,690
I just would like to use, although red light, which will be this red color.

27
00:01:43,170 --> 00:01:47,850
OK, so now we have the wrong option border here and the correct option border, which had trouble.

28
00:01:47,860 --> 00:01:53,610
So there just well, basically images, so to speak, that we can now use in our project.

29
00:01:53,970 --> 00:02:01,740
So the idea is that our possible options should be colored accordingly if we answered them correctly

30
00:02:01,740 --> 00:02:02,700
or incorrectly.

31
00:02:04,720 --> 00:02:12,280
And in order to find out what was selected or assigned a color, let's just say this way, I'm going

32
00:02:12,280 --> 00:02:18,460
to create a new variable, which I'm going to call answer, review and it needs to know the answer.

33
00:02:19,780 --> 00:02:27,250
And it needs to know the tribal view and to draw a view, while you might think it's an image or something

34
00:02:27,250 --> 00:02:30,190
like that, it's just going to be the integer, which is just, uh.

35
00:02:30,760 --> 00:02:34,420
Well, the location of the trouble, so to speak.

36
00:02:34,420 --> 00:02:39,820
Each of them has an idea and it's an integer, so we can just assign it this way so we can check the

37
00:02:39,820 --> 00:02:43,420
answer and we can use a Winklevoss here because it's an integer.

38
00:02:43,750 --> 00:02:53,290
And if the answer is one, what I'm going to do is I'm going to set the option one background.

39
00:02:55,260 --> 00:02:57,870
To be fair, draw view color.

40
00:02:58,050 --> 00:03:03,180
So whatever the job of you is that I want to assign whether it's red or blue or green, I'm going to

41
00:03:03,180 --> 00:03:04,020
just assign that.

42
00:03:04,230 --> 00:03:09,660
And we can just use the context compared once again with the get to draw bill, which will then give

43
00:03:09,660 --> 00:03:10,620
me the trouble.

44
00:03:10,620 --> 00:03:18,030
I need, however, to pass in the context as well as the integers that a view that I want to assign

45
00:03:18,040 --> 00:03:18,870
so get rubble.

46
00:03:19,320 --> 00:03:27,570
This method it requires, as you can see here, a national context as well as an integer, which is

47
00:03:27,570 --> 00:03:31,590
the Trouble Resources ID. And that's exactly what I'm passing here.

48
00:03:31,950 --> 00:03:34,720
Now we need to do the same thing with the other options.

49
00:03:34,740 --> 00:03:37,170
So I'm just going to copy them in here.

50
00:03:38,820 --> 00:03:44,720
And the only difference is really that there's no Option two that we are assigning this to.

51
00:03:44,760 --> 00:03:50,510
Then we have option three for the number three and option four for the number for accordingly.

52
00:03:50,520 --> 00:03:56,010
So depending on what the answer is, so if the answer is one or the answer is two or the answer is three

53
00:03:56,010 --> 00:03:56,700
and so forth.

54
00:03:57,690 --> 00:04:05,190
OK, so that's the answer that the user selected and the color that we're going to assign depends on

55
00:04:05,190 --> 00:04:07,080
whether we were right or wrong.

56
00:04:07,860 --> 00:04:10,650
So let's assign the code for that.

57
00:04:11,070 --> 00:04:19,589
Therefore, once we click on the submit button, what I want to do is I want to check if the selected

58
00:04:20,519 --> 00:04:21,149
option.

59
00:04:22,019 --> 00:04:27,630
So the selected option position is zero because that's what it is by default.

60
00:04:27,900 --> 00:04:32,460
And then I'm going to increase the current position by one, which means I'm going to go to the next

61
00:04:32,460 --> 00:04:34,050
question, so to speak.

62
00:04:34,290 --> 00:04:38,070
So I'm selection option position equals equals zero.

63
00:04:38,460 --> 00:04:40,290
Let's see why I'm using zero.

64
00:04:40,500 --> 00:04:45,150
Well, that's because zero is the selected option by default.

65
00:04:45,150 --> 00:04:52,620
So I just set this value to zero, and whenever we select an answer, it will be overriding the value

66
00:04:52,620 --> 00:04:52,920
there.

67
00:04:53,550 --> 00:04:53,970
OK.

68
00:04:54,120 --> 00:04:57,210
So that's our current position.

69
00:04:57,750 --> 00:05:09,090
And what I'm going to do is as long as I have questions left, I'm going to ask the next question.

70
00:05:09,300 --> 00:05:10,350
So here I am.

71
00:05:10,830 --> 00:05:17,160
Current position less or equal, I'm questions list size.

72
00:05:17,970 --> 00:05:23,490
So that size in that case, let me set the question.

73
00:05:24,560 --> 00:05:31,610
So it's just going to call this question method that we have created earlier where we set the new image,

74
00:05:31,610 --> 00:05:35,900
where we set the question, as well as the possible options.

75
00:05:36,650 --> 00:05:38,270
OK, so now.

76
00:05:39,730 --> 00:05:43,660
This is when we submit and selected option position was set to zero.

77
00:05:44,800 --> 00:05:48,640
Otherwise, what I want to do is I want to get the question.

78
00:05:48,970 --> 00:05:56,260
So here I am questions list and I need that because I need to know at which position we are and what

79
00:05:56,260 --> 00:05:57,310
the correct answer is.

80
00:05:57,310 --> 00:06:00,760
So, and current position minus one.

81
00:06:01,860 --> 00:06:09,510
And this will just give me the question that fits to the current question that I'm at because the current

82
00:06:09,510 --> 00:06:17,340
position is going to be, you see here increased by one and it's going to be one by default.

83
00:06:17,730 --> 00:06:21,780
And because an ArrayList starts counting at zero.

84
00:06:22,050 --> 00:06:26,510
So this question's list starts counting at zero and has its indexes.

85
00:06:26,520 --> 00:06:27,960
We just need to add this minus one.

86
00:06:28,830 --> 00:06:29,280
So now.

87
00:06:30,290 --> 00:06:32,120
We can check if the question.

88
00:06:32,780 --> 00:06:33,770
Correct answer.

89
00:06:36,120 --> 00:06:43,440
It's going to be the same or not the same, so selected options position.

90
00:06:43,860 --> 00:06:49,710
And here are some questions, but the question and because question is a Nullarbor as it contains a

91
00:06:49,710 --> 00:06:55,140
Nullarbor as its answer, we need to use the double question marks or we assigned another bill to it,

92
00:06:55,440 --> 00:07:01,600
which now means it's another bill itself as well, which if you want to use it, you need to force unwrap

93
00:07:01,680 --> 00:07:01,800
it.

94
00:07:02,400 --> 00:07:04,110
So here we can now.

95
00:07:04,110 --> 00:07:06,420
Or you can, of course, use the your light and so forth.

96
00:07:06,420 --> 00:07:11,910
But I'm not going to go into debt to make it even more complicated in this case.

97
00:07:12,420 --> 00:07:15,510
So here we can call the answer view.

98
00:07:15,510 --> 00:07:22,860
Now we can pass in the selected option that we selected as the user and can pass into the image that

99
00:07:22,860 --> 00:07:23,970
we want to use.

100
00:07:24,270 --> 00:07:27,090
So what I'm going to use is the wrong option.

101
00:07:27,090 --> 00:07:36,300
Border background So if the answer was incorrect, I'm going to select that and display the red background

102
00:07:36,720 --> 00:07:39,030
and otherwise or in general.

103
00:07:39,030 --> 00:07:40,020
So let me.

104
00:07:41,000 --> 00:07:47,780
Get those curly brackets here, and in general, what I'm going to do is I'm going to colored the correct

105
00:07:47,780 --> 00:07:48,350
answer.

106
00:07:49,410 --> 00:07:56,880
Print, so here, question that correct answer should be art dot, drobo dot.

107
00:07:57,360 --> 00:07:59,820
Correct option border background.

108
00:08:00,840 --> 00:08:03,150
OK, so that's what this.

109
00:08:04,710 --> 00:08:06,660
The thing you will do for me, let's run this.

110
00:08:06,720 --> 00:08:09,600
Let's see if this is going to do the trick for us.

111
00:08:10,620 --> 00:08:17,880
So here, submit you see Argentina was correct, so it shows me the correct color and that was stupid

112
00:08:17,880 --> 00:08:19,590
of me to select the right answer.

113
00:08:20,670 --> 00:08:21,520
I was stupid of me.

114
00:08:21,540 --> 00:08:24,240
Now let's select Australia and you see the wrong one.

115
00:08:24,270 --> 00:08:26,670
Got the red colour and the right one got the green color.

116
00:08:26,670 --> 00:08:33,690
So no matter if we are wrong or right, the right color will always be turning green, so it will always

117
00:08:33,690 --> 00:08:34,710
get this correct option.

118
00:08:34,710 --> 00:08:35,580
Border background.

119
00:08:36,360 --> 00:08:41,820
So now I also want to check if I'm at the end of my questions and want to jump to the next question.

120
00:08:41,820 --> 00:08:42,900
So let me click submit.

121
00:08:43,450 --> 00:08:45,270
You see, we don't get to the next question.

122
00:08:45,540 --> 00:08:47,610
So let's get to the next question.

123
00:08:48,720 --> 00:08:55,530
And therefore, I'm going to first check if the current position and here and details to a global variable

124
00:08:55,950 --> 00:08:58,620
is equal to the amount of questions that I have.

125
00:09:00,490 --> 00:09:04,840
And if that's the case, I'm going to set the button.

126
00:09:06,560 --> 00:09:09,080
Submit text, how do they call this button?

127
00:09:09,530 --> 00:09:11,600
I think I called it beat and submit.

128
00:09:12,140 --> 00:09:13,700
So he had BTN submit.

129
00:09:13,770 --> 00:09:18,290
Yeah, I'm going to set that text to finish.

130
00:09:19,730 --> 00:09:23,060
And otherwise, I'm going to set it to be.

131
00:09:24,620 --> 00:09:25,550
Go to next question.

132
00:09:26,970 --> 00:09:32,470
So here, button submit the text will be go to next question and this was button submit.

133
00:09:32,660 --> 00:09:33,570
So in my case?

134
00:09:34,860 --> 00:09:43,590
And what's really important is no matter what I need to set back the selected option position to zero

135
00:09:43,590 --> 00:09:51,540
because otherwise we will always stay at the current selected option and we will get areas where the

136
00:09:51,540 --> 00:09:53,280
app will not behave as we wanted to.

137
00:09:55,050 --> 00:09:57,180
OK, so now let's go ahead and test this.

138
00:09:59,870 --> 00:10:05,930
Let's go here, let's of the wrong one that seems to work, the tax changes to go to next question.

139
00:10:06,260 --> 00:10:09,260
And now you see, oh, that doesn't seem to have reset.

140
00:10:09,530 --> 00:10:13,690
So the colors have not reset, but at least we are on the next question, which is great.

141
00:10:13,700 --> 00:10:19,790
OK, so you see, the progress bar has changed the progress bar text view as well as the image has changed.

142
00:10:19,970 --> 00:10:24,740
While the question, technically speaking, also has changed, even though it's the exact same same

143
00:10:24,740 --> 00:10:28,010
question, but yeah, every option has changed.

144
00:10:28,010 --> 00:10:32,870
So all of that seems to work flawlessly, except for the resetting of the colors.

145
00:10:34,960 --> 00:10:40,450
And now where would be a good spot to reset the questions?

146
00:10:40,900 --> 00:10:48,730
Well, option colors to reset them to our default where this method called default options view, which

147
00:10:48,730 --> 00:10:52,270
we had set up this one here, where would be a good spot to call it?

148
00:10:52,750 --> 00:10:56,020
Well, I'd say at the moment where we set the question.

149
00:10:56,350 --> 00:11:03,010
So here we can just go ahead and call this method where we reset all of the options to be great again.

150
00:11:03,160 --> 00:11:04,540
So let's run that real quick.

151
00:11:06,200 --> 00:11:07,640
And let's under a name.

152
00:11:08,360 --> 00:11:12,260
Let's select Armenia, even though it's incorrect, go to next question.

153
00:11:12,300 --> 00:11:13,700
You can see now it's reset.

154
00:11:14,600 --> 00:11:18,950
OK, so now let's just go to the end and we have multiple problems.

155
00:11:18,950 --> 00:11:21,650
Still, you can see we can submit even without selecting something.

156
00:11:22,040 --> 00:11:25,130
And then once we are at the end, we click on finish and nothing happens.

157
00:11:25,340 --> 00:11:33,770
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.

158
00:11:33,830 --> 00:11:38,960
So I believe that would be here when we don't have any more questions.

159
00:11:39,290 --> 00:11:45,500
So here else or not else, but we're in a one class, so we need to do it slightly differently here.

160
00:11:47,940 --> 00:11:55,770
And then else, like so because we are in a weight class, so we're using the lambda expression here.

161
00:11:56,010 --> 00:12:00,150
And what I'm going to say for now, it's just going to be a toast.

162
00:12:00,480 --> 00:12:08,220
OK, so toast, make text and you see here I need to pass in the context and say what I want to display.

163
00:12:09,080 --> 00:12:10,200
Uh, congrats.

164
00:12:10,500 --> 00:12:11,070
You've made it.

165
00:12:12,390 --> 00:12:14,610
Yeah, made it to the end.

166
00:12:16,110 --> 00:12:16,540
Okay.

167
00:12:18,640 --> 00:12:18,940
All right.

168
00:12:19,000 --> 00:12:19,990
Let's try this once again.

169
00:12:21,420 --> 00:12:25,140
And make it to the end to solve some in some and some bits and submit.

170
00:12:25,290 --> 00:12:26,430
And you made it to the end.

171
00:12:26,790 --> 00:12:32,160
So of course, we want to send the user down to a results screen where you can then see how many questions

172
00:12:32,160 --> 00:12:33,480
he has correct and so forth.

173
00:12:33,750 --> 00:12:36,360
But for now, that will do the trick.

174
00:12:38,240 --> 00:12:45,530
And by the way, this I wrote, what is problem with just clicking on submit, submit, submit to something

175
00:12:45,530 --> 00:12:50,540
we're not going to change for now because maybe the user doesn't know and he just wants to submit and

176
00:12:50,810 --> 00:12:52,250
he doesn't even want to select something.

177
00:12:52,850 --> 00:12:54,890
OK, so that's it for this video.

178
00:12:55,430 --> 00:13:01,520
See you in the next one where we are going to prepare the UI for the result activity or actually we

179
00:13:01,520 --> 00:13:04,580
need to look at how to start activity for result works first.

180
00:13:04,940 --> 00:13:05,690
So let's see there.

