Welcome back in this week, we're going to set up our exercise recycler view adaptor because we want
to display the status of our exercise, we want to know at which exercise we're currently at.
Are we at the jumping jacks?
Are we at the wall said.
Exercise push up and so forth.
And we also would like to know how many exercises we have in total.
So here at the bottom, it should display all of that.
OK, so let's go ahead and set that up.
Therefore, we will need to create a recycler view adaptor or an adapter as such that we can then use
forward to recycle you.
So let's create a new Scotland class, and I'm going to call this one exercise steadies adapter because
it will just take care of the status.
So basically of the number of exercise that we are currently at.
So when you want to use this adapter for a recycler view, you need to follow a structure.
So the structure is always the same.
And I hope you checked out the demo for the basics of recyclable use using the few binding concepts
as well.
So we're going to require a ArrayList or a list.
Of some sort that will be displayed inside of this recycled view.
Otherwise, it wouldn't make sense, right?
So you need to have some sort of list of items that you want to display there.
So in my case, I'm just going to call them items, which will be a list items of exercise model.
And there's a separate list like so so there will be of time exercise model, which is our individual
exercises.
So they will have an idea, a name and image and known whether they are completed or are currently selected.
So these two will be very useful for our status because we will know that the completed once should
get a particular background color and the selected one should get a different color and the noncompete
one will get again a different color.
OK, so this will just allow us to see which exercises we still have to do once we just quickly glance
at the phone.
All right.
So if you want this to be used for a recycler, do you need to make sure that this is going to be a
recycler view adapter?
So here, recycler, if you don't add up to where you then need to pass a view holder to.
OK, so here we're going to pass in our own view holder.
So let me put that in a separate line, so it will be a little more readable.
So here this will be the exercise status adapter view holder.
Thought view all the.
And here, the holder with a capital H.
Mike, so now this doesn't exist yet, but we're going to create our own class inside of our exercise
status view holder.
And how does that work?
Well, this is going to be an internal class.
So he has class.
You hold her hand here because we're using view binding, we need to pass the view binding to it.
So item exercise.
Studies binding is what we are going to pass, and it will be just a recycler view view holder.
So we're going to inherit from the View hold a class to which we then need to pass the view binding
object again.
So binding that route.
OK, so this is our view holder.
How it's going to be in general and now we can access its items.
So, for example, I can access to text your item to be binding dot TV item.
So what is this TV item?
It's this individual item that we have here, of which we will have 12 because we have 12 exercises.
But that's the whole point.
If we had one exercise because we decide that we don't want to make it the seven minute workout, but
the name in the workout app, then we could very easily just add additional items to it.
OK.
And our quote was still work.
All right.
So we have this vault TV item.
So let's actually use it because if you create a adapter, you need to implement a couple of members
and the members that you must implement are on create view holder on bind view holder and get item count.
So these three methods.
So let's just click the button and you see it creates all of those methods for us, which we now need
to implement.
So on create view holder, that's where we want to return our own view, hold that it would just create.
So let's return it.
Return view holder and we need to pass in the binding.
So here we can just go ahead and use item exercise status binding, inflate where we then use to layout
inflator.
But we need to get it from somewhere and we're going to get it from the parents context because we cannot
just pass this as this recycled.
If you doesn't have its own context, it needs to use the context from its parent, which will then
use the context from the activity that it's it.
All right.
So then we also need to pass in.
The parent, as well as whether we want to attach to parents and we're going to say we don't want to
attach to parents, so let me put that in a separate line.
So that's going to be the structure whenever you are using a reactive you with your own view holder
in a default fashion.
OK, so we have the uncreative you holder here, which is an override function.
So it's given to us and we need to return something that is of type you holder.
All right.
So let's do exactly that.
We return to view holder to which we, if we look at it, need to pass a binding object of type item
exercise that is binding, which is exactly what we do here, but we also need to inflate it.
And if you want to inflate it outside of a activity, which is what we are at, we are inflating inside
of a adapter or an adapter.
And now we need to pass in the layout inflator from as given context.
And then we can pass in the view group, which is our parent, and we're not going to attach to it.
Oh, we're not going to attach to the parent.
So then what should happen for every single item when the view is bound?
So on by-nd view holder?
Well, what I want to get is the model of our exercise model.
So exercise model, which will be items at the position that we're currently at.
So what are items again?
Well, it's this items object that gets here.
So once we create an adapter object, we will need to pass and the list of exercise models.
And if you recall in exercise activity, we have exactly that.
So here we have this exercise list, which is an array list of exercise model.
So we'll need to pass in this exercise list later on.
So we're passing this exercise list of individual exercise models and then we get the one.
So the exercise list item at the position that we are currently at one binding the view holder.
So in our case, this method will be called 12 times because we have 12 view holders that we will bound
for each position.
One.
OK, so here position is an integer and we are passing basically and three zero and three, two, one
and three two and so forth, or position zero position one position to and so forth.
And all of these will be individual items that will be displayed next to each other, which will just
look like this little circle circle one, Circle two, Circle three, Circle four and so forth.
You will see that once we're done with it.
So now I can use this model in order to access its ID.
So Holder Dot text your item dot text should be the model dot get ID Dot to string.
So what's happening here?
Well, we are getting the idea as a string from our model.
So what is that?
Well, our model is this exercise model, which has an ID with which we now get, but it's of type integer.
So now we're converting it into a string.
And what do we assign it to?
Where sign it to our holders?
Text your item.
Text property.
So what is this holder again?
Well, it's this holder that is our own view holder, and we can now access this text view item object.
OK, so this one in particular, not this one, but we're getting this one in particular.
So we're getting the text item, which is going to be connected to the text to your item, which is
this thing here.
And then we actually assign an ID or a number to it.
OK, so we're basically assigning the exercise numbers here.
So number one for jumping jacks?
Number two for Wall, said number three.
Four, push up and so forth.
And now we just need to also return how many items we will have in total inside of this recycler view.
And here you just need to return the items that size.
So basically, whatever array list is given to the adapter that size and our case, it's the items.
In your case, it could be whatever you want to call it, that size.
OK, so this by itself, unfortunately, is not going to be enough to show anything because we are not
connecting this adapter.
As you see, it's gray.
We're not connecting it yet to the adapter that we have inside of our exercise somehow.
So here.
Activity exercise, we have our recycler view at the very bottom, this one.
Now we just need to assign the adapted.
We just created to disrespect a view and set it up accordingly, saying that it should not be a list
that is a vertical list, but it should be a horizontal list and so forth.
And that's what we're going to do in the next video.
So see you there.