Welcome back.
Now that we have the item task, it's time to add the adapter for our RV card list for this of you.
All right.
So we will need an adapter.
Of course, each time that we use a recycler view, we, of course, need to give it an adapter.
So let's prepare that, OK?
And we're going to do that in the adapters folder.
So let's create a new file class.
And I'm just going to call this one task list item adapter.
All right, so here, this one will be an open class so that we can inherit from it and we will use
the default constructor here as we have it, private volle context, context.
So pretty much the same thing as we have with the board items.
Adaptor is going to be very similar, but there are some minor changes here as well.
So private var list, which is an array list of.
Task.
So we will need to have a new class called task.
And we have already actually let me see.
Yes, we have it already.
OK, so we created this little task which has a title and is created by so perfect.
We prepared it already.
So now we can go ahead and import it.
So import task and then import context as well.
And here it's the Android context when it comes to task.
There are also multiple choices and I want to use the one that we created.
So you thought of project management or Project Monash.
That's the name of our project, OK.
And of course, this should inherit from Recycler View Adapter.
With a recital of you.
That view holder.
All right, nothing too fancy here.
We've done that multiple times before, so let's close the bracket and just like that.
OK, so once we add all of that.
Like this, we need to make sure that recyclable use there, but it does it seems the error disappeared.
So it's there and now we can go ahead and implement the missing function.
So implement members here.
As usual, that's all of those members or at all of those members, so we have the uncreate view holder
get item cound and on bond fueler.
Now, this time, we will need to make minor changes to what we usually would do, OK?
Usually we would just take the whole space available and our view holder would just be the hole with.
Right.
But this time, what I will do is I will just make it 70 percent.
OK, so you can see here it's roughly 70 percent of the screen with that we are using.
And that's what I want to do.
So I want this to recyclability, of course, also just have a certain percentage of the screen available.
So once we wipe over to the other side, we can still see that there are more lists.
OK, so that's the idea behind this.
You can, of course, change the value, if you like, 80 or 90 percent more than than what I'm using
here, but I'm just going to work with 70 percent.
So in order to do that, I will need to create a function which calculates that correctly.
OK, so it has to calculate the width into density pixels.
So let me just create a new function here, which will do that private fun int to DP will return an
integer.
OK, and what this will do is it will just do this thought or resources, get the system.
Todd display metrics.
Sheer resources needs to be imported so that we can use it and the standard resources and here we can
now get the display metrics that density.
And now we want to transfer that into an integer, so to and that is it looks a little confusing, I'd
say, but what it does is basically it allows us to get the density of the screen and convert that into
an integer so that we see how big the density pixel value is so that we can then adjust our width of
the application accordingly.
All of this adapter list items adapter.
So we get the density pixel from the pixel.
And now let's get the pixel from the density pixel.
So now we do it the other way around.
So let me just copy this code here, because now we use to P x.
Okay.
So you maybe recall TP stands for density pixel P, X stands for Pixel.
And by the way, I think I'll just use DPE with the capital and P non capitalized.
So to dip here and to X here and now.
This time it's not dividing by but it's multiplying by and we want to multiply it with the density to
it.
OK, so the one way is to divide it, the other way is to multiply it.
So now we have both directions.
So this one gets us the pixel from density pixel and this one gives us the density pixel from pixel.
Now, as we always do, we create a little class here, which is my view, holder, view, view, recycler.
View that view holder.
And here we just passed into view, so you here now we need to import, view and enter, import it and
it's under a dark view that we want to use.
So this view Holder describes an item view and metadata about its place within the sight of you.
So that's the idea behind this class here.
OK, now let's go ahead and implement all of the functions that we have here.
So the easiest one will be get item count.
So here we're just going to return the list that size.
Easy one.
Right.
Then we have our function, which is the unbind view holder here.
We first of all, get the.
Position and and of the position, we can create our model, which is list at position, so whatever
list we get at any position given, we will get the model from it.
So in one case, it was the board.
In this case it will be the task.
So now our model will be the task because we are in the task list items adapter.
And here at the top we get the list of tasks of, let's say, idea of a religious task.
OK, so now we get the model and we can now check if the holder is our recycler of UV holder, if that
one is the my view holder.
So the one that we just prepared here at the bottom.
OK, so if that's the case, then go ahead and check if the position is equal to list that size minus
one.
So if the position is equal to the list size, whatever that is, let's say we have no entries there,
minus one, then we want to display our task list.
TextView, OK, so then we want to display this ad, least I text you pretty much right.
So let's just do that.
Let's just say holder dot item, view dot TV.
Our task list visibility should be the view that visible.
OK, what do we want to make invisible or gone in that case?
Well, all of the rest, right.
So Holder item view l l on this core task item, visibility should be said to view dot com.
I guess what this is l'oeil task item is basically, as you can see, everything underneath.
So this whole part here, which is all of the stuff that has to do with the individual carts.
So every little task item that we have inside of our list, that should not be visible then.
OK, so that's the idea here behind this code that we have here, so the taxpayers should be visible
if we have no entries in our list and.
The other stuff should not be visible, but if we have an entry on our list.
Then we want to do it the other way around.
OK, so then we just basically want to do the same code as here.
Only that now this one should be gone and this one should be.
Visible.
So this TV ad task list.
If you look at it so here, I only want to display this ad list, if there is no list, as soon as there
is a list, I don't want to have this ad list I can hear.
Instead, I want to have the title of the element with all of the different cards.
And if there are no cards, of course, I want to prepare the cards.
So I want to create a new card more.
Add a new card.
OK, so this is our unbind view, holder, as you can see, it's a little more complex than what we
have had before.
Then.
We need to look at our creative view, holder, that's this one here.
So what we want to do here is, of course, to inflate our view, which is our item task.
So basically this whole exome that we prepared.
So Vul view lay out inflator.
Not from context inflate or dot layout dot.
And it's this item to ask.
This, of course, only works if we import our and now the in-flight function, as you might recall,
needs some more information here.
So then it needs to have the review group and the attached to route, which I'm going to set falls,
as we have done multiple times before, by default.
OK, now we want to set the linear layout as the layout parameters.
So layout parameters, layout paradigms.
It's going to be a linear layout.
Don't lay out parameters, so lay out programs, and here we can define the layout parameters of the
linear layout that we want to use.
And the thing is, I want to use the parent with so the width of the whole screen and multiply that
with seven point seven.
And then make an integer out of it again, because this function here does layout parents needs an integer,
and then I can pass in the layout programs, prep content.
So this is something that we have not done before, but basically what I'm doing with this code here
is I'm just saying, OK, the view holder should be point seven times the width of the parent of the
screen, pretty much that we have available and make an integer out of it, because that's what the
real parents require.
So it requires a with and a height.
So as the width, we just use point seven as as the height we say use Øvrebø content.
So use only as much height as you require.
So that's basically what we define here with the layout parents.
OK, then basically what we're doing here is we do XML stuff, right.
So we just create our own code to use XML stuff.
OK, now we can go ahead and set the margin for our layout parameters.
So basically this layer of parents variable that's just there to add a lot of parameters that you want
to have for your layout.
And I'm just going to say that it should create some margins or have some margins.
I'm going to use 15 to DPE and then I need to make it to pixels again to be X again, and then I need
to say what the top and the bottom is.
So basically what I'm doing here is I want to have margins and the left and right hand side, but none
at the top and bottom.
OK, so I'm just saying.
Here it should be.
By the way, it's like this, and then we have to come on here, so then it's zero and 40 to DPE.
Two pixels and zero.
OK, so this looks a little more confusing, but basically I'm just saying, OK, I want to have 15
margin towards the left and for the margins to what's the right?
OK, because look at margins.
Left is the first entry Topo's to second, right is the third, and bottom is the last one.
So as the first entry I'm saying use 15 density pixels, then zero, then 40, then zero.
So you can see why we need this to DPN to here.
It's a little counterintuitive, but that's how we have to handle this situation here.
All right.
And then we can set those layout parameters for our view.
We can just say layout parameters.
The ones that we prepared should be the one used for our view here.
And then we can return my view.
Holder.
With the view that we just prepared, so now everything comes together, right?
It was a little confusing before I think about we have prepared this view Holder, which requires a
view which basically is just a result of your view.
Holder So it inherits from it.
But we want to use our own view.
Holder Here.
We want to return our own view.
Holder.
With all of those settings, so we'll create a new view, we say it should be this item task view,
which is this XML file that we prepared here, but then we adjust it in the code.
So then we just say, OK, just take point seven of the width and wrap your content to what's the height?
Then have a little margin towards the left and right hand side.
And then we just assign those layout parameters that we prepared here in those lines.
We assign them to the view that we prepared here at the top and then we pass it to our my view holder,
which will then be the one that will be created once the screen is displayed or once this adapter is
prepared.
OK, so this is the task list item adapter.
Now let's use it in our tasks list activity, because that's what we prepared it for.
Right.
So now and fun board details.
So I'm setting up the action bar.
Right.
But at the same time, I also need to load all of the tasks.
So I'm just going to say at task list should be a task.
Which I'm going to import here, and the first task will be the ad list, so it's just the resources
to be prepared.
So it's a string here.
It's this atlast string, this one here.
OK.
So then.
Once I have that, I can use that task list to be added to my task list, so it looks a little weird,
but basically what I'm saying is my task list off the board.
So our board has a task list.
So let's look at the board here.
You can see it has this task list.
And now I'm adding to the task list, which is this array list here instead of our board.
I am adding.
The ad task list.
So just just text here, which is just going to say add a list, even though it's not really part of
the task list.
Right.
It's just a UI element, but there's just a workaround that we're working with here.
So that's how we can make our UI completely codependent or based on events instead of just being a fixed
UI that we have there.
And then we can go ahead and set our RV task list layout manager to be the linear layout manager that
we've come to love with this and.
The setting, that element should be horizontally positioned and reverse.
Layout is such a false.
OK.
So let me put that into line so it's a little more readable.
Then I'm just going to say that it should have a fixed size so said has fixed size, said to Drew,
and now we can prepare the adapter.
So let's go ahead and create an adapter, which will be our task list items adapter.
So it's this class that we prepared, of course.
And here we need to pass in the context and the list that we want to display.
And and it's our board DOT task list that we want to pass.
OK, I know we can set that as the RV task list adapter so we can say, OK, depth that we just prepared
is going to be the adapter of the arbutus.
This so this whole thing that we prepared in this items adapter is just here for this line of code here,
actually, just as the task list items adapter that we prepared where we needed to pass in the context
of the task list of of our board.
And that's what we get here.
We get a bunch of tasks and array list of tasks, and then we can do all of the magic that we just prepare.
And now before we test that, we, of course, need to add all of the images that we are still lacking.
OK, so if we look at our item task list, which we prepared in the last video, we still have a bunch
of errors here.
See cancel.
I see.
Done so all of these images are still missing.
So let's add those to our project as well.
Therefore, you can download the project which is assigned to this chapter, and then you can go to
your troubles folder.
Actually, to your resources folder is going to be fine, so show an explorer and then do the same thing
with the other project and then paste all of the drawable stuff in here.
So just.
Mark, all of that and pasted in from the other project.
OK, so just copy this code here and paste it into this one and skip the files that we have already
prepared right now at this point.
We can run the application.
I hope the error should disappear or will disappear.
So let's run it again.
Now we have this icey council.
I see the lead.
I see down at it.
So these are the images that are used now.
OK, and that we aren't now, let's open up a board, let's see if our application crashes.
No, it doesn't.
You can see the atlas takes the view is here.
OK, so that is it for this video.
It is a lot of stuff that comes together now, so it's really important that you have seen all of the
basics and learned all of the basics, be forced to understand all of the new stuff that we're using
here.
But I think at this point, we have prepared everything we need to do in order to now load data and
display it.
And there are still, of course, quite some changes that we will need to do on the way.
But so far I think so.
Good.
And now let's go over to the next video.
And thanks a lot for still being with me after this long video.
See you in the next one.