1
00:00:01,530 --> 00:00:02,040
Welcome back.

2
00:00:02,220 --> 00:00:07,920
And this video we're going to set up the recycler views so that it actually uses the adapter that we

3
00:00:07,920 --> 00:00:08,460
had set up.

4
00:00:08,460 --> 00:00:13,980
So you can see here we have those 12 exercises here at the bottom, even though they will not be highlighted

5
00:00:14,400 --> 00:00:17,100
as the selected one, for example, as of yet.

6
00:00:17,340 --> 00:00:18,990
But we're going to implement that later on.

7
00:00:18,990 --> 00:00:21,630
For now, it's important to just display the risk of you.

8
00:00:21,900 --> 00:00:23,880
OK, so that's what we're going to do in this video.

9
00:00:24,120 --> 00:00:28,440
So let's get back to our project and inside of our exercise activity.

10
00:00:28,440 --> 00:00:36,240
We will need to create an adapter object of our exercise status adapter that we had set up.

11
00:00:36,600 --> 00:00:43,650
OK, so let's do just that private VAR exercise adapter.

12
00:00:43,930 --> 00:00:51,180
OK, and that will be a exercise status adapter object, which will be another bullet for now, and

13
00:00:51,180 --> 00:00:52,650
I'm going to assign all to it.

14
00:00:53,010 --> 00:00:56,910
So this is basically just the adapter that we created in the last video.

15
00:00:57,270 --> 00:01:02,370
It's our own class that we created, and now we can create objects from it, which we just did.

16
00:01:02,730 --> 00:01:07,200
OK, now we can use this adapter to assign to our respective you as an adapter.

17
00:01:07,740 --> 00:01:10,800
OK, so where would be a good spot to do that?

18
00:01:12,250 --> 00:01:17,440
Well, I would say in the create method, but as the create method, there's something that we don't

19
00:01:17,440 --> 00:01:18,530
want to overload.

20
00:01:18,550 --> 00:01:24,340
Let's create a new method which will take care just of this plane, this recital of you at the bottom.

21
00:01:24,610 --> 00:01:29,410
So let's create a private function called set up exercise.

22
00:01:30,670 --> 00:01:32,640
Stead is recycler.

23
00:01:34,070 --> 00:01:34,380
Phew.

24
00:01:34,670 --> 00:01:40,610
OK, so this result of you now will take care of all of the good stuff, which means, first of all,

25
00:01:40,940 --> 00:01:46,010
we will set the respective use layout manager.

26
00:01:46,220 --> 00:01:53,150
OK, so here are the exercise studies dot layout manager.

27
00:01:53,630 --> 00:02:00,230
And this is, by the way, our exercise that is recycler view, which is this item directly inside of

28
00:02:00,230 --> 00:02:01,760
our user interface, OK?

29
00:02:02,390 --> 00:02:06,950
And now we can assign a layout manager property to it.

30
00:02:07,190 --> 00:02:14,150
So the layout manager property allows you to make such changes as whether you want this to be a grid

31
00:02:14,150 --> 00:02:20,300
view where items are positioned like in a grid, or whether you want to position items next to each

32
00:02:20,300 --> 00:02:25,010
other than the layout manager should be a horizontal, linear layout manager.

33
00:02:25,220 --> 00:02:30,860
If you want to put them on top of each other, it would be a vertical linear layout manager and so forth.

34
00:02:31,250 --> 00:02:39,320
So let's use a linear layout manager object here, which needs to have a context, and I'm going to

35
00:02:39,320 --> 00:02:44,480
pass this as the exercise activity should be the context of this layout manager.

36
00:02:44,780 --> 00:02:48,500
And then I can use the different setting.

37
00:02:48,500 --> 00:02:52,410
So you see we have horizontal vertical and invalid offset.

38
00:02:52,440 --> 00:02:57,740
So I want to use horizontal because I want my items to be positioned next to each other.

39
00:02:58,010 --> 00:03:02,670
And then you can say whether it should be displayed in the reverse order.

40
00:03:03,260 --> 00:03:04,970
And I'm going to say false.

41
00:03:05,120 --> 00:03:08,840
So I don't want to have a reverse layout here.

42
00:03:08,960 --> 00:03:09,350
OK.

43
00:03:09,440 --> 00:03:11,880
So set that to false if you don't want it to be reverse.

44
00:03:12,590 --> 00:03:14,720
This is just a linear layout manager.

45
00:03:14,900 --> 00:03:18,800
For example, there are grid layout managers, for example, as well.

46
00:03:18,810 --> 00:03:23,750
So you could, for example, create a grid labeled manager here and check what it requires.

47
00:03:23,780 --> 00:03:24,030
OK.

48
00:03:24,050 --> 00:03:26,840
It requires the context and then disband.

49
00:03:26,840 --> 00:03:30,320
Count the orientation and reverse layout.

50
00:03:30,320 --> 00:03:32,330
So I would use this third option here.

51
00:03:32,540 --> 00:03:39,530
So if you wanted to display it in a grid format, which I don't want to do, I want to use the linear

52
00:03:39,530 --> 00:03:43,580
layout manager, which allows me to put them next to each other, but just to give you an idea of what

53
00:03:43,580 --> 00:03:46,010
you can use as your layout managers.

54
00:03:46,850 --> 00:03:47,200
OK.

55
00:03:47,430 --> 00:03:55,310
And now I need to assign a value to my exercise adapter because I want to assign it as the adapter for

56
00:03:55,310 --> 00:03:56,990
my RV exercise status.

57
00:03:57,320 --> 00:03:59,360
So you always need to do two things for that.

58
00:03:59,870 --> 00:04:03,050
A recycler view that you have as an example.

59
00:04:04,450 --> 00:04:04,920
Widget.

60
00:04:05,090 --> 00:04:11,230
OK, so you need to assign a layout manager and you need to assign what the layout manager property

61
00:04:11,560 --> 00:04:17,649
and you need to assign a value to the adapter property of that right result of you.

62
00:04:18,160 --> 00:04:22,510
And yeah, let's go ahead and prepare the adapter so that we can assign it.

63
00:04:22,810 --> 00:04:29,800
And this will be our exercise status adapter and it needs a list of exercises.

64
00:04:29,800 --> 00:04:33,190
So I'm just going to pass our exercise list at this point.

65
00:04:33,550 --> 00:04:39,790
Now, if I force unwrap it, it's really important that this method set up exercise studies recycler

66
00:04:39,790 --> 00:04:45,070
view will not be called in the create method before we have assigned the exercise list.

67
00:04:45,310 --> 00:04:48,010
So I'm just going to call it at the very bottom here.

68
00:04:48,400 --> 00:04:55,420
Now, of course, the alternative would be to double check if the list isn't empty and only then create

69
00:04:55,420 --> 00:04:56,190
this object.

70
00:04:56,200 --> 00:05:02,710
But by following this structure, where we get that list first and then we call this method, we're

71
00:05:02,710 --> 00:05:03,340
good to go.

72
00:05:03,490 --> 00:05:03,770
OK.

73
00:05:03,790 --> 00:05:05,200
That's why we can focus on it.

74
00:05:05,530 --> 00:05:07,370
But this is something we have to be careful.

75
00:05:07,370 --> 00:05:07,780
Wolf, right?

76
00:05:07,810 --> 00:05:13,180
Just so you're aware this could go wrong if you don't have the right order of your code.

77
00:05:13,810 --> 00:05:21,190
OK, so now I just need to use a my recycler view exercise status.

78
00:05:22,300 --> 00:05:30,430
Adapter, I just need to assign the exercise adapter to the accessories status, race, active use adapter.

79
00:05:31,000 --> 00:05:36,130
OK, so let's just do that exercise adapter, and that will be pretty much it.

80
00:05:36,760 --> 00:05:39,280
So now let's go ahead and test this.

81
00:05:40,700 --> 00:05:44,740
And let's see whether it will display their respect of you.

82
00:05:46,060 --> 00:05:49,690
As we wanted, so not as we wanted, but it displays it.

83
00:05:50,020 --> 00:05:51,310
All right, so there we are, you see?

84
00:05:51,790 --> 00:05:53,270
Get ready for jumping jacks.

85
00:05:53,600 --> 00:05:56,350
And it displays our recycle view here at the bottom.

86
00:05:56,710 --> 00:06:02,440
Now I want it to be centered, and how I can achieve that is by going over to my exercise.

87
00:06:02,440 --> 00:06:08,500
And also let me jump out of it because I don't want to have something in the background and make sure

88
00:06:08,500 --> 00:06:12,820
that the start and end of are the parents.

89
00:06:13,630 --> 00:06:17,590
OK, so here lay out constrained and off and start off.

90
00:06:18,040 --> 00:06:20,740
This will make sure that our item is centered.

91
00:06:21,190 --> 00:06:25,900
So our respect, if you will now be centered, let's rerun it and see if that's actually the case.

92
00:06:26,590 --> 00:06:26,980
So.

93
00:06:28,110 --> 00:06:28,800
Not yet.

94
00:06:28,910 --> 00:06:31,500
OK, let me check what else could be the issue here.

95
00:06:35,000 --> 00:06:40,160
And I believe we could fix it by also just wrapping the content in terms of with.

96
00:06:40,380 --> 00:06:42,170
Okay, that should do the trick.

97
00:06:42,620 --> 00:06:46,700
Because just adding start and end off will not be enough.

98
00:06:47,270 --> 00:06:48,410
And let's see, there we are.

99
00:06:48,560 --> 00:06:54,740
So now of wrapping its content and it's being dragged to the sides, but it's also being pulled to the

100
00:06:54,740 --> 00:06:55,340
bottom.

101
00:06:55,730 --> 00:06:59,260
And it has while it is underneath our jumping jacks.

102
00:06:59,270 --> 00:07:04,580
So that's pretty much what I wanted to have in terms of the respect of you behavior.

103
00:07:06,670 --> 00:07:08,740
OK, so let's summarize what's going on here.

104
00:07:09,100 --> 00:07:16,370
So we have this recycle view here at the bottom, which is basically just this recycling of you Exim

105
00:07:16,420 --> 00:07:17,410
L widget.

106
00:07:17,530 --> 00:07:21,420
OK, so at the very bottom of our activity exercise, we have this widget.

107
00:07:21,440 --> 00:07:27,100
OK, this recycle of you and the recycle view needs to know how items are positioned, so it needs to

108
00:07:27,100 --> 00:07:30,080
know about the linear or the layout manager.

109
00:07:30,080 --> 00:07:33,910
It doesn't have to be a linear layout manager, but that's what we are using because we want to put

110
00:07:33,910 --> 00:07:35,980
items next to each other.

111
00:07:35,980 --> 00:07:39,580
As you can see here, they are not on top of each other, but next to each other.

112
00:07:40,090 --> 00:07:41,650
And it needs an adapter.

113
00:07:41,890 --> 00:07:48,430
So we created this linear layout manager here in order to assign it.

114
00:07:48,490 --> 00:07:51,640
So this one, in order to assign it to our of you.

115
00:07:52,000 --> 00:07:58,060
And then we need to create an adapter in order to assign it to the adapter property of the recycle view.

116
00:07:58,270 --> 00:08:00,790
OK, so this recycler view needs to have an adapter.

117
00:08:00,910 --> 00:08:05,650
And now, in order to assign an adapter, we of course need to prepare an adapter, which is what we

118
00:08:05,650 --> 00:08:05,920
did.

119
00:08:06,100 --> 00:08:11,650
So we created this adapter, which needs to have an array list or a list in general, doesn't have to

120
00:08:11,650 --> 00:08:12,240
be realistic.

121
00:08:12,250 --> 00:08:17,020
It could be another type of list, but it needs to have a list of items that it's supposed to display.

122
00:08:17,260 --> 00:08:23,710
And in our case, it's going to be in a list of exercise model items so which are just our exercises,

123
00:08:23,740 --> 00:08:26,860
like every single exercise, has an ID and name and so forth.

124
00:08:27,430 --> 00:08:33,669
And now we are just saying that our adapter should inherit from recycled view adapter.

125
00:08:33,730 --> 00:08:35,900
And here we're passing our own view holder.

126
00:08:36,130 --> 00:08:42,159
So we're saying use the view holder from the exercise status adapter for your type.

127
00:08:42,159 --> 00:08:48,580
So we're saying, OK, we create our own view holder class inside of our exercise status adapter class

128
00:08:48,910 --> 00:08:54,190
and we pass in our binding object, which is the item exercise that is binding.

129
00:08:54,580 --> 00:09:02,980
And then we can also use the binding in order to use the Recycler View View holder, which is just a

130
00:09:02,980 --> 00:09:03,790
normal view holder.

131
00:09:03,790 --> 00:09:10,390
And we pass our binding route, which means we're passing our recycler view by item itself.

132
00:09:10,720 --> 00:09:11,150
OK.

133
00:09:11,440 --> 00:09:18,310
And then we can now access its items so we can access the text view item, which is this item exercise

134
00:09:18,520 --> 00:09:22,120
status, which is this text view item.

135
00:09:22,150 --> 00:09:27,340
OK, so this text view that we created an extra example file for item exercise status.

136
00:09:27,610 --> 00:09:30,220
So this is how an individual item should look like.

137
00:09:30,970 --> 00:09:37,210
So now we have to implement those three methods to get item count is the one.

138
00:09:37,210 --> 00:09:41,500
Where would you say, how many items do we have inside of this item's proper?

139
00:09:41,880 --> 00:09:49,180
The array lists or how many different elements are or exercises are inside of this list of exercises?

140
00:09:49,810 --> 00:09:54,580
Then we say what we want to do for every single binding of a view holder.

141
00:09:54,580 --> 00:10:02,860
So for every single one of those little circles, and what we're saying is just assigned the idea of

142
00:10:02,860 --> 00:10:07,270
the number of the exercise to the circle.

143
00:10:07,690 --> 00:10:13,300
So to the text of the circle, to be more precise, because this TV item has a text property that we're

144
00:10:13,300 --> 00:10:14,320
now overwriting.

145
00:10:14,370 --> 00:10:21,250
OK, so we're setting the text of this TV item where we are while binding it, in our view, all before,

146
00:10:21,250 --> 00:10:21,580
right?

147
00:10:21,850 --> 00:10:24,020
We're just assigning our ID to it.

148
00:10:24,490 --> 00:10:29,380
Of the model, which is our exercise model, which is basically our exercise.

149
00:10:29,920 --> 00:10:35,860
OK, and now we're just assigning it here and in the concrete view holder there, we need to return

150
00:10:35,860 --> 00:10:37,960
our own view, hold that we just created.

151
00:10:37,990 --> 00:10:40,000
At least that's our approach to it.

152
00:10:40,180 --> 00:10:44,450
And we are passing something of type binding to the view holder.

153
00:10:44,530 --> 00:10:47,320
What is the binding that we're passing, where the binding object is?

154
00:10:47,320 --> 00:10:53,620
Our item exercise status binding, which we get through using view binding and we inflate.

155
00:10:54,770 --> 00:11:01,370
And therefore, we need to pass in a layout inflator, and we get that from the parents context, so

156
00:11:01,370 --> 00:11:07,910
the parent is the view group and then we need to pass in the view group itself, as well as say, whether

157
00:11:07,910 --> 00:11:09,710
we want to attach it to the parent or not.

158
00:11:10,460 --> 00:11:11,330
OK, and now.

159
00:11:12,400 --> 00:11:18,730
At this point, we can assign this adapter that we've just created to our recycling of you.

160
00:11:19,150 --> 00:11:26,620
So we do that inside of our exercise activity, so set up exercise studies, which give you is how I

161
00:11:26,980 --> 00:11:33,400
called the function and to me, call it correctly and the recycler view like so.

162
00:11:34,290 --> 00:11:42,870
So I had a typo in there, and now this will basically do the trick of assigning everything, setting

163
00:11:42,870 --> 00:11:49,500
the layout that we wanted in our case that items are positioned horizontally, which you can see here

164
00:11:49,500 --> 00:11:50,010
clearly.

165
00:11:50,940 --> 00:11:51,380
OK.

166
00:11:51,420 --> 00:11:56,520
So that's it for this video and the next one, we're going to see how we can display at which exercise

167
00:11:56,520 --> 00:12:02,940
we currently are because you see, I'm at high knees running in place, which is we could check that

168
00:12:02,940 --> 00:12:03,310
out.

169
00:12:03,850 --> 00:12:05,100
Um, no.

170
00:12:06,060 --> 00:12:07,200
Or is it triceps?

171
00:12:07,530 --> 00:12:08,640
It's number nine.

172
00:12:09,390 --> 00:12:14,580
So I would like to make sure that nine is going to have a different background.

173
00:12:14,700 --> 00:12:15,960
So see you in the next video.

