1
00:00:00,970 --> 00:00:07,030
Welcome back in this video, I'm going to set up the adapter that we're going to require in order to

2
00:00:07,030 --> 00:00:10,480
display this information into our recycle, you see here.

3
00:00:10,840 --> 00:00:14,560
We want to display the database entries onto our recycler view.

4
00:00:14,560 --> 00:00:16,690
Therefore, we need to set up an adapter.

5
00:00:16,930 --> 00:00:21,640
And of course, the respect of you as well and then assign that adapter to the recycler of you in the

6
00:00:21,640 --> 00:00:23,350
main activity where we display this.

7
00:00:23,680 --> 00:00:28,690
So what we will need, however, is something slightly different to what we have built so far.

8
00:00:28,930 --> 00:00:36,190
So the recyclables that we use of our we didn't pass listeners to the adapter itself, and that's what

9
00:00:36,190 --> 00:00:37,750
we're going to do in this video.

10
00:00:37,960 --> 00:00:43,480
So for example, I have this listener that listens or waits for me to click on this update button or

11
00:00:43,510 --> 00:00:44,560
on this delete button.

12
00:00:45,190 --> 00:00:47,920
So let's go ahead and implement that and this video.

13
00:00:47,920 --> 00:00:50,860
We're going to focus on the adapter itself to then display stuff.

14
00:00:50,860 --> 00:00:54,280
And then later we can see how we can add, delete and add it.

15
00:00:54,580 --> 00:01:00,250
So let's get back to our project and let's go ahead and create a new adapter, which I'm going to call

16
00:01:00,280 --> 00:01:01,660
item adapter.

17
00:01:03,020 --> 00:01:08,810
So this will be the adapter class that will take care of individual items, and this one will accordingly,

18
00:01:09,050 --> 00:01:14,660
of course, inherit from the recycler view adapter class.

19
00:01:14,960 --> 00:01:20,780
And here we need to pass into view holder and I'm going to have a view holder inside of the item adapter.

20
00:01:20,780 --> 00:01:25,880
So a custom view holder in a class that we're creating, but it's not going to be an inner class as

21
00:01:25,880 --> 00:01:26,150
such.

22
00:01:26,150 --> 00:01:28,430
It's just going to be a class that is inside of this class.

23
00:01:28,880 --> 00:01:35,600
So I'm going to call this a view holder, which is going to require a binding, which we can get from.

24
00:01:35,600 --> 00:01:40,370
The items are all binding type or which will be of type items, roll binding.

25
00:01:41,790 --> 00:01:42,190
OK.

26
00:01:42,300 --> 00:01:44,250
And why items rope binding?

27
00:01:44,280 --> 00:01:47,760
Well, because that's how we called our example file.

28
00:01:48,120 --> 00:01:49,710
It's called items Rolex, somehow.

29
00:01:49,830 --> 00:01:52,170
So that's why the binding is called items rule binding.

30
00:01:53,100 --> 00:01:59,340
OK, so we're just saying, OK, we want to have the example that we prepared there to be used.

31
00:02:00,210 --> 00:02:00,720
So.

32
00:02:01,800 --> 00:02:03,210
This items, for example.

33
00:02:04,320 --> 00:02:08,639
OK, now this, of course, will be of type recycled view view holder.

34
00:02:08,880 --> 00:02:16,350
OK, we need to use the view holder and we need to pass in the route, which if you hold control and

35
00:02:16,350 --> 00:02:23,130
click on, it is going to be this item are and El Heron view or layout, which is this linear layout

36
00:02:23,130 --> 00:02:25,170
in my case, which I called allow.

37
00:02:26,190 --> 00:02:31,500
So now I want to have access to all of the items inside of it, which means all of the views, the text

38
00:02:31,500 --> 00:02:32,940
views and image views.

39
00:02:33,510 --> 00:02:37,020
Therefore, what I'm going to do in here is I'm going to set them up.

40
00:02:37,260 --> 00:02:43,380
Also, by the way, also the main view or the main layout, which is the linear layout.

41
00:02:44,310 --> 00:02:49,340
So we'll get that via l'Allemagne, because that's the name of the linear layout idea.

42
00:02:49,390 --> 00:02:50,010
l'Allemagne.

43
00:02:50,880 --> 00:02:53,760
OK, now we need to do the same thing with the other items.

44
00:02:54,480 --> 00:02:58,410
So with our text views and our image views.

45
00:02:58,590 --> 00:03:01,500
So text you email name, edit and delete.

46
00:03:02,040 --> 00:03:03,720
We get them via your binding.

47
00:03:05,070 --> 00:03:11,220
OK, so now we can use this view holder here, so we're going to use our item adapter, you holder,

48
00:03:11,220 --> 00:03:13,170
which is this class that we created ourselves.

49
00:03:13,410 --> 00:03:16,230
This one here, then we need to add the brackets here.

50
00:03:16,470 --> 00:03:22,760
And of course, what's really important is we need now to pass into a list that we want to use.

51
00:03:22,770 --> 00:03:24,560
And in our case, of course, is an array list.

52
00:03:24,990 --> 00:03:27,060
So let's go ahead and pass it.

53
00:03:27,310 --> 00:03:37,350
Private vol items, which is going to be an array list of our employee entity because our entity is

54
00:03:37,350 --> 00:03:40,620
our model, which we are also using for our database.

55
00:03:41,730 --> 00:03:49,110
OK, so now our item adaptor, of course, needs to have the members so needs to have those three members

56
00:03:49,110 --> 00:03:52,140
on create if you hold the armband view holder and get item count.

57
00:03:52,560 --> 00:03:54,030
So let's auto add them.

58
00:03:54,400 --> 00:03:58,800
But what I'm also going to add here, and this is the thing that I was talking about that is new that

59
00:03:58,800 --> 00:04:04,620
we haven't done before is I'm going to add an updated listener, which is just going to wait for us

60
00:04:04,980 --> 00:04:11,130
to click on the update button and I'm going to add a delete listener, which is just going to wait for

61
00:04:11,130 --> 00:04:12,900
us to click on the delete button.

62
00:04:13,590 --> 00:04:15,360
OK, so that's how it's done.

63
00:04:15,900 --> 00:04:17,730
We're just saying, OK, the update.

64
00:04:17,740 --> 00:04:23,730
Listen, there's going to be of this type, which is the expression that we're using here.

65
00:04:23,730 --> 00:04:26,640
We're passing an I.D. and we get the units.

66
00:04:28,960 --> 00:04:34,180
OK, so now let's implement those the easiest one is going to be get item count.

67
00:04:34,510 --> 00:04:41,470
And this one will just be our items that list or size better said, and we need to return that.

68
00:04:42,100 --> 00:04:46,390
So item size will return an integer, which is what we need to return here.

69
00:04:47,020 --> 00:04:50,620
So now what should happen once we create our view holder?

70
00:04:50,860 --> 00:04:52,290
Well, usually we just return.

71
00:04:52,300 --> 00:04:53,170
If you hold Holder, OK?

72
00:04:53,530 --> 00:04:54,910
So let's return a view.

73
00:04:54,910 --> 00:04:58,540
Hold their object here, which now requires our binding object.

74
00:04:58,810 --> 00:05:06,220
And in order to create the binding object, we use our items role binding inflate with the layout inflator.

75
00:05:06,400 --> 00:05:13,510
But because we are inside of a different context and not inside of the context of an activity, we need

76
00:05:13,510 --> 00:05:16,810
to use the following approach where we get the context from the parent.

77
00:05:17,830 --> 00:05:23,940
OK, and then we pass the parents, as well as whether we want to attach it to root.

78
00:05:24,220 --> 00:05:25,690
So it's going to look like this.

79
00:05:26,200 --> 00:05:31,060
We get the Parent View Group, which is passed to us when we create a view holder.

80
00:05:31,720 --> 00:05:37,840
OK, so once it's created, we return to view holder, which will return an object of this class.

81
00:05:38,260 --> 00:05:42,430
And now we can use that view holder and bind its individual items.

82
00:05:42,850 --> 00:05:46,990
So what I want to do here is I want to have a context.

83
00:05:47,230 --> 00:05:49,090
Otherwise, I can't do some of the magic.

84
00:05:49,450 --> 00:05:52,570
So hold your dot item view context.

85
00:05:53,080 --> 00:05:59,200
So we get the context from the holder itself, which has an item view property and then the context.

86
00:05:59,470 --> 00:06:00,640
So here we get the context.

87
00:06:01,300 --> 00:06:07,450
And now we need to get the individual item and we get that from our items list that is passed to this

88
00:06:07,450 --> 00:06:08,050
adapter.

89
00:06:09,010 --> 00:06:14,410
And we need to say at which position we want to have it because the item will be the individual item

90
00:06:14,410 --> 00:06:19,660
of our items, this which is going to be just an employee entity item.

91
00:06:19,990 --> 00:06:25,240
OK, so this item will be an employee entity object.

92
00:06:26,170 --> 00:06:28,530
So now what else do we want to do?

93
00:06:28,540 --> 00:06:35,530
Because now we need to assign the text, view this text view and we need to make sure that those buttons

94
00:06:35,530 --> 00:06:36,070
are going to work.

95
00:06:36,580 --> 00:06:39,910
And also, you can see if you look at it, the color changes.

96
00:06:40,150 --> 00:06:46,060
OK, so the background color is changing so that we have this effect, which is a good approach.

97
00:06:47,300 --> 00:06:52,280
So first of all, let's make sure that we get access to the text, you name, text.

98
00:06:53,240 --> 00:06:55,760
And we pass the item name.

99
00:06:56,210 --> 00:06:59,450
So the name, if you look at it, is this name.

100
00:06:59,870 --> 00:07:07,160
So this is employee entity, object or item is of type, employee object or entity, to be more precise.

101
00:07:07,700 --> 00:07:15,290
So we get its name, property and assign it to the text will name text, property and then we need to

102
00:07:15,350 --> 00:07:16,730
do the same thing with the email.

103
00:07:17,870 --> 00:07:20,690
And here we just get Item Dot email.

104
00:07:22,130 --> 00:07:23,570
And then we.

105
00:07:25,240 --> 00:07:27,280
Add the color background thing to OK.

106
00:07:27,340 --> 00:07:30,880
Therefore, I needed to have this l'Allemagne here.

107
00:07:31,120 --> 00:07:34,490
OK, so that I can change the background of the linear layout item.

108
00:07:35,230 --> 00:07:40,030
So here if position is modulo two.

109
00:07:40,210 --> 00:07:49,450
So every second object, so to speak, I am going to change the cut background color, so set background

110
00:07:49,450 --> 00:07:52,780
color of my linear layout.

111
00:07:52,990 --> 00:07:55,630
And here I'm just going to use context compared.

112
00:07:57,990 --> 00:07:59,610
Get color, too, then.

113
00:08:01,010 --> 00:08:03,860
Get the color to our holder.

114
00:08:03,980 --> 00:08:07,710
So here we need to pass in the context so that we can change the color.

115
00:08:07,730 --> 00:08:13,190
So here we get the context and then we set the color itself.

116
00:08:13,190 --> 00:08:14,720
So our colored dot.

117
00:08:15,380 --> 00:08:17,450
And we have color light gray.

118
00:08:17,690 --> 00:08:18,410
I think we don't.

119
00:08:18,950 --> 00:08:19,700
Let's set that up.

120
00:08:19,850 --> 00:08:21,600
Color light gray.

121
00:08:22,820 --> 00:08:26,450
OK, so I'm going to set this color up in my colors x am alpha.

122
00:08:26,600 --> 00:08:29,060
So let's create a color resource.

123
00:08:31,330 --> 00:08:32,350
And their colors.

124
00:08:33,940 --> 00:08:34,570
Color.

125
00:08:35,580 --> 00:08:37,919
Name will be light, Ray.

126
00:08:41,559 --> 00:08:44,680
We're just going to be this color here.

127
00:08:46,510 --> 00:08:54,760
So, E.B., BBB, OK, which is quite close to a white, but it's not exactly white, as you see here,

128
00:08:55,150 --> 00:08:56,380
just a little bit gray.

129
00:08:57,370 --> 00:09:01,150
And now let's see if we can use it, actually.

130
00:09:01,170 --> 00:09:02,320
They call it color.

131
00:09:03,290 --> 00:09:05,180
Like, I think I call it like Ray.

132
00:09:05,720 --> 00:09:07,160
Let me see like Ray.

133
00:09:07,550 --> 00:09:13,100
So let's use the same name instead of the color six email file, and now we should be good to go.

134
00:09:13,670 --> 00:09:19,220
OK, so every second item is going to be gray now, and the other items are going to be whatever is

135
00:09:19,220 --> 00:09:20,450
the default, which is white.

136
00:09:21,630 --> 00:09:26,100
Even though we can also manually set that, so let's do that real quick.

137
00:09:27,700 --> 00:09:28,450
So here.

138
00:09:30,090 --> 00:09:33,870
Let me set that color to be the white color.

139
00:09:33,990 --> 00:09:36,930
And let me add a white color as well.

140
00:09:39,360 --> 00:09:41,160
And actually, we just called it white.

141
00:09:42,360 --> 00:09:44,400
So let's use this white color here.

142
00:09:45,850 --> 00:09:54,880
And now in here, we can set on click items, OK, and once we click on one of those items here, either

143
00:09:54,880 --> 00:10:02,020
this one or that one will need to handle that in the online view holder as well, which the problem

144
00:10:02,020 --> 00:10:10,270
is that this item adapter doesn't inherit or doesn't implement the click listener's, which is why we

145
00:10:10,270 --> 00:10:11,710
need to pass the on click listener.

146
00:10:11,890 --> 00:10:14,140
So the update listener, as well as the Delete listener.

147
00:10:14,680 --> 00:10:15,700
So now let's use those.

148
00:10:16,300 --> 00:10:19,180
Let's use Holder Dot, I've added.

149
00:10:19,240 --> 00:10:25,540
So once we click on in the interview edit button or image you, we want to set that on click listener

150
00:10:25,540 --> 00:10:25,900
to it.

151
00:10:26,980 --> 00:10:30,850
And here I'm going to use to update listener to invoke.

152
00:10:33,370 --> 00:10:34,840
Something with the item ID.

153
00:10:35,920 --> 00:10:42,490
So we're invoking the update listener, which means we are doing a click, so to speak, and we're passing

154
00:10:42,490 --> 00:10:42,910
the ID.

155
00:10:44,020 --> 00:10:49,480
This will make a lot more sense once we get over to domain activity where we are also going to actually

156
00:10:49,480 --> 00:10:50,020
use this.

157
00:10:50,680 --> 00:10:53,020
So now we need to do the same thing with the delete listener.

158
00:10:53,620 --> 00:10:54,730
So let's do that.

159
00:10:54,860 --> 00:10:56,860
I.V. Delete.

160
00:10:58,210 --> 00:11:00,970
And this one will be the delete a lesson there.

161
00:11:01,600 --> 00:11:06,340
So we invoke again with the item because we need to know which item was clicked and we get that from

162
00:11:06,340 --> 00:11:08,660
the item that we're currently at.

163
00:11:08,680 --> 00:11:12,860
Because if you look at it, everything, well, we have this button multiple times, right?

164
00:11:12,880 --> 00:11:15,690
We have this button here with us here where this year and we have this year.

165
00:11:15,700 --> 00:11:18,100
So even though it's an immature you, but it behaves like a button.

166
00:11:18,430 --> 00:11:22,870
So each time we click on it, it needs to know which of the items we clicked it on.

167
00:11:23,110 --> 00:11:27,550
So did we click it on the Dennis One tab, we click the Edit button on the Frank one, on the Mike one

168
00:11:27,550 --> 00:11:28,090
and so forth.

169
00:11:28,330 --> 00:11:34,990
It needs to know this and it gets it inside of the online if you hold it because they're it notes which

170
00:11:34,990 --> 00:11:35,830
button was clicked.

171
00:11:36,160 --> 00:11:44,620
So here we can say, OK, the current item that we are in for that the object lesson that was clicked

172
00:11:45,100 --> 00:11:46,180
and let's invoke it.

173
00:11:46,450 --> 00:11:51,850
So let's call the update listener, which we then of course, will need to implement in the main activity

174
00:11:51,850 --> 00:11:53,410
to be clickable.

175
00:11:54,840 --> 00:12:00,360
So we're going to get those through creating the item adapter inside of our main activity.

176
00:12:01,230 --> 00:12:01,620
OK.

177
00:12:01,950 --> 00:12:07,110
So unfortunately, there's not much to see yet in this video, but I believe it really makes sense to

178
00:12:07,110 --> 00:12:10,500
have a break here because otherwise this video would be way too long.

179
00:12:10,740 --> 00:12:16,740
So in the next video, we're going to then finally display everything because we prepared our item adapter

180
00:12:16,740 --> 00:12:17,020
now.

181
00:12:17,040 --> 00:12:23,730
Let's go ahead and assign it to the recycle view in our main activity, which if we look at it, is

182
00:12:23,730 --> 00:12:24,150
this.

183
00:12:25,360 --> 00:12:30,190
One down here, there's this recycler, view this one.

184
00:12:30,910 --> 00:12:37,570
And now we need to assign our item adapter to it and pass the list of items that we want to display,

185
00:12:37,570 --> 00:12:40,360
which is going to be something that we get from the database.

186
00:12:40,900 --> 00:12:42,280
OK, so that's it for this video.

187
00:12:42,290 --> 00:12:43,060
See you in the next one.

