Welcome back.
And this video we're going to set up the recycler views so that it actually uses the adapter that we
had set up.
So you can see here we have those 12 exercises here at the bottom, even though they will not be highlighted
as the selected one, for example, as of yet.
But we're going to implement that later on.
For now, it's important to just display the risk of you.
OK, so that's what we're going to do in this video.
So let's get back to our project and inside of our exercise activity.
We will need to create an adapter object of our exercise status adapter that we had set up.
OK, so let's do just that private VAR exercise adapter.
OK, and that will be a exercise status adapter object, which will be another bullet for now, and
I'm going to assign all to it.
So this is basically just the adapter that we created in the last video.
It's our own class that we created, and now we can create objects from it, which we just did.
OK, now we can use this adapter to assign to our respective you as an adapter.
OK, so where would be a good spot to do that?
Well, I would say in the create method, but as the create method, there's something that we don't
want to overload.
Let's create a new method which will take care just of this plane, this recital of you at the bottom.
So let's create a private function called set up exercise.
Stead is recycler.
Phew.
OK, so this result of you now will take care of all of the good stuff, which means, first of all,
we will set the respective use layout manager.
OK, so here are the exercise studies dot layout manager.
And this is, by the way, our exercise that is recycler view, which is this item directly inside of
our user interface, OK?
And now we can assign a layout manager property to it.
So the layout manager property allows you to make such changes as whether you want this to be a grid
view where items are positioned like in a grid, or whether you want to position items next to each
other than the layout manager should be a horizontal, linear layout manager.
If you want to put them on top of each other, it would be a vertical linear layout manager and so forth.
So let's use a linear layout manager object here, which needs to have a context, and I'm going to
pass this as the exercise activity should be the context of this layout manager.
And then I can use the different setting.
So you see we have horizontal vertical and invalid offset.
So I want to use horizontal because I want my items to be positioned next to each other.
And then you can say whether it should be displayed in the reverse order.
And I'm going to say false.
So I don't want to have a reverse layout here.
OK.
So set that to false if you don't want it to be reverse.
This is just a linear layout manager.
For example, there are grid layout managers, for example, as well.
So you could, for example, create a grid labeled manager here and check what it requires.
OK.
It requires the context and then disband.
Count the orientation and reverse layout.
So I would use this third option here.
So if you wanted to display it in a grid format, which I don't want to do, I want to use the linear
layout manager, which allows me to put them next to each other, but just to give you an idea of what
you can use as your layout managers.
OK.
And now I need to assign a value to my exercise adapter because I want to assign it as the adapter for
my RV exercise status.
So you always need to do two things for that.
A recycler view that you have as an example.
Widget.
OK, so you need to assign a layout manager and you need to assign what the layout manager property
and you need to assign a value to the adapter property of that right result of you.
And yeah, let's go ahead and prepare the adapter so that we can assign it.
And this will be our exercise status adapter and it needs a list of exercises.
So I'm just going to pass our exercise list at this point.
Now, if I force unwrap it, it's really important that this method set up exercise studies recycler
view will not be called in the create method before we have assigned the exercise list.
So I'm just going to call it at the very bottom here.
Now, of course, the alternative would be to double check if the list isn't empty and only then create
this object.
But by following this structure, where we get that list first and then we call this method, we're
good to go.
OK.
That's why we can focus on it.
But this is something we have to be careful.
Wolf, right?
Just so you're aware this could go wrong if you don't have the right order of your code.
OK, so now I just need to use a my recycler view exercise status.
Adapter, I just need to assign the exercise adapter to the accessories status, race, active use adapter.
OK, so let's just do that exercise adapter, and that will be pretty much it.
So now let's go ahead and test this.
And let's see whether it will display their respect of you.
As we wanted, so not as we wanted, but it displays it.
All right, so there we are, you see?
Get ready for jumping jacks.
And it displays our recycle view here at the bottom.
Now I want it to be centered, and how I can achieve that is by going over to my exercise.
And also let me jump out of it because I don't want to have something in the background and make sure
that the start and end of are the parents.
OK, so here lay out constrained and off and start off.
This will make sure that our item is centered.
So our respect, if you will now be centered, let's rerun it and see if that's actually the case.
So.
Not yet.
OK, let me check what else could be the issue here.
And I believe we could fix it by also just wrapping the content in terms of with.
Okay, that should do the trick.
Because just adding start and end off will not be enough.
And let's see, there we are.
So now of wrapping its content and it's being dragged to the sides, but it's also being pulled to the
bottom.
And it has while it is underneath our jumping jacks.
So that's pretty much what I wanted to have in terms of the respect of you behavior.
OK, so let's summarize what's going on here.
So we have this recycle view here at the bottom, which is basically just this recycling of you Exim
L widget.
OK, so at the very bottom of our activity exercise, we have this widget.
OK, this recycle of you and the recycle view needs to know how items are positioned, so it needs to
know about the linear or the layout manager.
It doesn't have to be a linear layout manager, but that's what we are using because we want to put
items next to each other.
As you can see here, they are not on top of each other, but next to each other.
And it needs an adapter.
So we created this linear layout manager here in order to assign it.
So this one, in order to assign it to our of you.
And then we need to create an adapter in order to assign it to the adapter property of the recycle view.
OK, so this recycler view needs to have an adapter.
And now, in order to assign an adapter, we of course need to prepare an adapter, which is what we
did.
So we created this adapter, which needs to have an array list or a list in general, doesn't have to
be realistic.
It could be another type of list, but it needs to have a list of items that it's supposed to display.
And in our case, it's going to be in a list of exercise model items so which are just our exercises,
like every single exercise, has an ID and name and so forth.
And now we are just saying that our adapter should inherit from recycled view adapter.
And here we're passing our own view holder.
So we're saying use the view holder from the exercise status adapter for your type.
So we're saying, OK, we create our own view holder class inside of our exercise status adapter class
and we pass in our binding object, which is the item exercise that is binding.
And then we can also use the binding in order to use the Recycler View View holder, which is just a
normal view holder.
And we pass our binding route, which means we're passing our recycler view by item itself.
OK.
And then we can now access its items so we can access the text view item, which is this item exercise
status, which is this text view item.
OK, so this text view that we created an extra example file for item exercise status.
So this is how an individual item should look like.
So now we have to implement those three methods to get item count is the one.
Where would you say, how many items do we have inside of this item's proper?
The array lists or how many different elements are or exercises are inside of this list of exercises?
Then we say what we want to do for every single binding of a view holder.
So for every single one of those little circles, and what we're saying is just assigned the idea of
the number of the exercise to the circle.
So to the text of the circle, to be more precise, because this TV item has a text property that we're
now overwriting.
OK, so we're setting the text of this TV item where we are while binding it, in our view, all before,
right?
We're just assigning our ID to it.
Of the model, which is our exercise model, which is basically our exercise.
OK, and now we're just assigning it here and in the concrete view holder there, we need to return
our own view, hold that we just created.
At least that's our approach to it.
And we are passing something of type binding to the view holder.
What is the binding that we're passing, where the binding object is?
Our item exercise status binding, which we get through using view binding and we inflate.
And therefore, we need to pass in a layout inflator, and we get that from the parents context, so
the parent is the view group and then we need to pass in the view group itself, as well as say, whether
we want to attach it to the parent or not.
OK, and now.
At this point, we can assign this adapter that we've just created to our recycling of you.
So we do that inside of our exercise activity, so set up exercise studies, which give you is how I
called the function and to me, call it correctly and the recycler view like so.
So I had a typo in there, and now this will basically do the trick of assigning everything, setting
the layout that we wanted in our case that items are positioned horizontally, which you can see here
clearly.
OK.
So that's it for this video and the next one, we're going to see how we can display at which exercise
we currently are because you see, I'm at high knees running in place, which is we could check that
out.
Um, no.
Or is it triceps?
It's number nine.
So I would like to make sure that nine is going to have a different background.
So see you in the next video.