Welcome back in this video, I'm going to set up the adapter that we're going to require in order to
display this information into our recycle, you see here.
We want to display the database entries onto our recycler view.
Therefore, we need to set up an adapter.
And of course, the respect of you as well and then assign that adapter to the recycler of you in the
main activity where we display this.
So what we will need, however, is something slightly different to what we have built so far.
So the recyclables that we use of our we didn't pass listeners to the adapter itself, and that's what
we're going to do in this video.
So for example, I have this listener that listens or waits for me to click on this update button or
on this delete button.
So let's go ahead and implement that and this video.
We're going to focus on the adapter itself to then display stuff.
And then later we can see how we can add, delete and add it.
So let's get back to our project and let's go ahead and create a new adapter, which I'm going to call
item adapter.
So this will be the adapter class that will take care of individual items, and this one will accordingly,
of course, inherit from the recycler view adapter class.
And here we need to pass into view holder and I'm going to have a view holder inside of the item adapter.
So a custom view holder in a class that we're creating, but it's not going to be an inner class as
such.
It's just going to be a class that is inside of this class.
So I'm going to call this a view holder, which is going to require a binding, which we can get from.
The items are all binding type or which will be of type items, roll binding.
OK.
And why items rope binding?
Well, because that's how we called our example file.
It's called items Rolex, somehow.
So that's why the binding is called items rule binding.
OK, so we're just saying, OK, we want to have the example that we prepared there to be used.
So.
This items, for example.
OK, now this, of course, will be of type recycled view view holder.
OK, we need to use the view holder and we need to pass in the route, which if you hold control and
click on, it is going to be this item are and El Heron view or layout, which is this linear layout
in my case, which I called allow.
So now I want to have access to all of the items inside of it, which means all of the views, the text
views and image views.
Therefore, what I'm going to do in here is I'm going to set them up.
Also, by the way, also the main view or the main layout, which is the linear layout.
So we'll get that via l'Allemagne, because that's the name of the linear layout idea.
l'Allemagne.
OK, now we need to do the same thing with the other items.
So with our text views and our image views.
So text you email name, edit and delete.
We get them via your binding.
OK, so now we can use this view holder here, so we're going to use our item adapter, you holder,
which is this class that we created ourselves.
This one here, then we need to add the brackets here.
And of course, what's really important is we need now to pass into a list that we want to use.
And in our case, of course, is an array list.
So let's go ahead and pass it.
Private vol items, which is going to be an array list of our employee entity because our entity is
our model, which we are also using for our database.
OK, so now our item adaptor, of course, needs to have the members so needs to have those three members
on create if you hold the armband view holder and get item count.
So let's auto add them.
But what I'm also going to add here, and this is the thing that I was talking about that is new that
we haven't done before is I'm going to add an updated listener, which is just going to wait for us
to click on the update button and I'm going to add a delete listener, which is just going to wait for
us to click on the delete button.
OK, so that's how it's done.
We're just saying, OK, the update.
Listen, there's going to be of this type, which is the expression that we're using here.
We're passing an I.D. and we get the units.
OK, so now let's implement those the easiest one is going to be get item count.
And this one will just be our items that list or size better said, and we need to return that.
So item size will return an integer, which is what we need to return here.
So now what should happen once we create our view holder?
Well, usually we just return.
If you hold Holder, OK?
So let's return a view.
Hold their object here, which now requires our binding object.
And in order to create the binding object, we use our items role binding inflate with the layout inflator.
But because we are inside of a different context and not inside of the context of an activity, we need
to use the following approach where we get the context from the parent.
OK, and then we pass the parents, as well as whether we want to attach it to root.
So it's going to look like this.
We get the Parent View Group, which is passed to us when we create a view holder.
OK, so once it's created, we return to view holder, which will return an object of this class.
And now we can use that view holder and bind its individual items.
So what I want to do here is I want to have a context.
Otherwise, I can't do some of the magic.
So hold your dot item view context.
So we get the context from the holder itself, which has an item view property and then the context.
So here we get the context.
And now we need to get the individual item and we get that from our items list that is passed to this
adapter.
And we need to say at which position we want to have it because the item will be the individual item
of our items, this which is going to be just an employee entity item.
OK, so this item will be an employee entity object.
So now what else do we want to do?
Because now we need to assign the text, view this text view and we need to make sure that those buttons
are going to work.
And also, you can see if you look at it, the color changes.
OK, so the background color is changing so that we have this effect, which is a good approach.
So first of all, let's make sure that we get access to the text, you name, text.
And we pass the item name.
So the name, if you look at it, is this name.
So this is employee entity, object or item is of type, employee object or entity, to be more precise.
So we get its name, property and assign it to the text will name text, property and then we need to
do the same thing with the email.
And here we just get Item Dot email.
And then we.
Add the color background thing to OK.
Therefore, I needed to have this l'Allemagne here.
OK, so that I can change the background of the linear layout item.
So here if position is modulo two.
So every second object, so to speak, I am going to change the cut background color, so set background
color of my linear layout.
And here I'm just going to use context compared.
Get color, too, then.
Get the color to our holder.
So here we need to pass in the context so that we can change the color.
So here we get the context and then we set the color itself.
So our colored dot.
And we have color light gray.
I think we don't.
Let's set that up.
Color light gray.
OK, so I'm going to set this color up in my colors x am alpha.
So let's create a color resource.
And their colors.
Color.
Name will be light, Ray.
We're just going to be this color here.
So, E.B., BBB, OK, which is quite close to a white, but it's not exactly white, as you see here,
just a little bit gray.
And now let's see if we can use it, actually.
They call it color.
Like, I think I call it like Ray.
Let me see like Ray.
So let's use the same name instead of the color six email file, and now we should be good to go.
OK, so every second item is going to be gray now, and the other items are going to be whatever is
the default, which is white.
Even though we can also manually set that, so let's do that real quick.
So here.
Let me set that color to be the white color.
And let me add a white color as well.
And actually, we just called it white.
So let's use this white color here.
And now in here, we can set on click items, OK, and once we click on one of those items here, either
this one or that one will need to handle that in the online view holder as well, which the problem
is that this item adapter doesn't inherit or doesn't implement the click listener's, which is why we
need to pass the on click listener.
So the update listener, as well as the Delete listener.
So now let's use those.
Let's use Holder Dot, I've added.
So once we click on in the interview edit button or image you, we want to set that on click listener
to it.
And here I'm going to use to update listener to invoke.
Something with the item ID.
So we're invoking the update listener, which means we are doing a click, so to speak, and we're passing
the ID.
This will make a lot more sense once we get over to domain activity where we are also going to actually
use this.
So now we need to do the same thing with the delete listener.
So let's do that.
I.V. Delete.
And this one will be the delete a lesson there.
So we invoke again with the item because we need to know which item was clicked and we get that from
the item that we're currently at.
Because if you look at it, everything, well, we have this button multiple times, right?
We have this button here with us here where this year and we have this year.
So even though it's an immature you, but it behaves like a button.
So each time we click on it, it needs to know which of the items we clicked it on.
So did we click it on the Dennis One tab, we click the Edit button on the Frank one, on the Mike one
and so forth.
It needs to know this and it gets it inside of the online if you hold it because they're it notes which
button was clicked.
So here we can say, OK, the current item that we are in for that the object lesson that was clicked
and let's invoke it.
So let's call the update listener, which we then of course, will need to implement in the main activity
to be clickable.
So we're going to get those through creating the item adapter inside of our main activity.
OK.
So unfortunately, there's not much to see yet in this video, but I believe it really makes sense to
have a break here because otherwise this video would be way too long.
So in the next video, we're going to then finally display everything because we prepared our item adapter
now.
Let's go ahead and assign it to the recycle view in our main activity, which if we look at it, is
this.
One down here, there's this recycler, view this one.
And now we need to assign our item adapter to it and pass the list of items that we want to display,
which is going to be something that we get from the database.
OK, so that's it for this video.
See you in the next one.