Welcome back.
Now let's finalize the functionality of what we can actually select or at least we can display the different
selections that we have as options and something that I didn't specifically state in the last video,
which I wanted to do in this one, is that we are using something pretty cool here.
We are using view binding in research reviews.
So this is a more advanced concept, so to speak, when it comes to binding or view binding.
So usually we would use few binding and very simple uses, but when it comes to recycled views, it's
a little more complicated and that's really how you do it, basically.
OK, so that's the view binding jetpack kind of way, right?
So you're using jetpack here in order to get the most out of your application.
All right.
So then let's go ahead and add update activity stuff to her, add up to the activity.
So the first thing that we need to do is we need to create a new function here.
And I'm going to put it down there all the way down.
And it will be a private function, custom items, dialogue.
Now, it will need a title which will be of third string and it needs the items, a list of type list
string or a list of strings, so to speak, and the selection, which will also be a string.
So what is this custom items and dialogue?
Well, it's basically this thing here that shouldn't be displayed.
So this is a dialogue in which we then populate or inflate our recycler view, which has all of those
unique items in there.
Okay, so in order to have a custom dialogued, you, of course, need to set it up.
And I'm going to call this one customer list dialogue, which will just be a basic dialogue.
With our current context, which is this, which means the context of that current activity that we're
in, and then we're going to use data mining once again, but this time it will be dialogue, custom
list binding.
So, as you can see, this class has been able to generate for us as well, which is pretty cool.
And it is based on our dialogue customer list here on this XML.
So we are going to use it's binding in order to use its views, which means now we can access this Arvi
list and TV title and so forth.
OK, so let's do that.
And therefore I need to go back here so we have the binding ready almost.
Well, we prepared the variable, but we didn't assign it.
So we're going to use.
By custom, this binding inflate with the layout inflator.
Now we can go ahead and set the custom list dialog content for you to be binding that route.
So that will basically say that our custom, this dialogue should use the complete XML file that we
just looked at.
OK, so it's this.
Eye to eye closed it already, but it's the start of list.
OK, so it should basically use this linear layout as its complete layout, so as the layout of our.
Customers dialogue.
Of this pop up, so to speak.
OK, then we can use binding at this point to set the text, for example.
So the title to the title, text to be the title that is passed to this method, OK, to the custom
items dialogue as well as use binding for our recital of you.
So our V list layout manager is going to be our linear.
Layout manager.
With this as context, OK, so usually you wouldn't use binding here, but, well, in the past you
wouldn't have used binding here.
But as we are using a jet pack approach or we are using your binding here, which is part of jet pack,
we will use this approach, you see.
So we're setting the linear layout manager and now we can set up the adapter.
So I'm going to create an adapter object, which will be the custom list item adapter, which we created
in the last video to which we need to pass the activity.
So I'm going to pass this as well as the list that we want to display and then the selection.
OK, so whatever is selected, for example, and then bonding Arvi list.
Adapter should be the doctor that we just set up and then we can display our custom, this dialogue.
So if you watched the handwrote master masterclass, of course, that I created and learned from it,
you will have seen that exact approach, but without using view binding as well as without putting it
into a dialogue.
So now we are really putting things together, which adds complexity.
But it's good because now you're learning the highest what a higher level of complexity.
So what's going on here?
We are creating an adaptor object of our customer list item adapter, which is the class that we created
in the last video where we had to create a view holder, where we set up the binding, OK, and we inflated
it to be basically the ball used the layout inflator from that activity in which this jobholder will
be created.
So that's a good thing because that's, in fact, this activity.
So it's our ad update, the activity in which it is created.
Now, if you look at it, here's the top.
You see, you need to pass an activity, a list and a selection.
Guess what?
That's exactly what we do here.
We pass the activity, which is this.
We pass the items list, which is going to be passed to this method once this method is called.
And we pass a selection, which is also something that will be passed to this method once we call it.
So we, of course, need to call it at one point with the title as well as the items list and the selection
later on.
And then we set the recycler view to use that adapter.
And by the way, the layout manager that we assigned to our recycler view is the linear layout manager,
which means we're saying that the recycler of you should just use the linear layout approach, so to
speak.
It should be of type in your layout.
OK, and then we used as customised dialogue to show it here.
All right.
At this point, the customer list dialogue will be displayed with the items list that the user can then
select from.
Now, if it would run that nothing would happen because we never called this method, but before we
can call this method, we need to add something else, because that's something that I usually forget
and I want to do it straight away at the start.
So whenever you want to be able to click on any of the elements inside of your view, which is in our
case to type, for example, you need to set an on click listener to it.
So make sure that you do the same thing for all of the types that we have here.
So I added that category.
We need to add an oncologist here year as well and then unbinding that cooking time.
So these are the three where we need to add an unclick listener to them, because otherwise, if you
look at this so I'm click away here.
If you click on to type for example, nothing would happen.
So we need to add an unclick.
Listen to it now.
The type will then actually do something.
So now at this point we can go ahead and add the unclick events for all of those different buttons that
we have there.
So here.
Well, it's not really buttons, but those added text feels right.
So here where we had this Artaud idea where the idea was to, for example, add this image, we need
to add a couple more of those so that idot etty type.
So once we click, click on the adits text type.
Object of view, so to speak, then this code should be executed.
So what is the code that should be executed here?
Well, first of all, we want to call this custom items dialogue.
Which we created, which is.
There's method here from the very bottom custom items, dialogue, I should name it, custom list dialogue
or custom items list dialogue.
Well, it really depends on how you want to call it.
It's fine.
So custom items, a list, a dialogue.
Now, what is it that we need to pass to it?
Well, first of all, the title and here I'm going to use a string.
And I'm going to use the string from our resources, so we need to go ahead and go to our resources
to set it up there.
So let's go to our string XML file.
And add those titles that you want to have.
OK, so I want to have, for example, the selective type select type category, the dish cooking time.
And as you can see, these are going to be the texts that I want to use there.
So these are the titles that I want to use in there.
OK, now we can actually use that string resource.
We also need to pass the constraints that dish types.
So this will then be our dish types list and then Constance.
Dish.
So here once again, Konstanz dish type, so we need to say which thingee we selected.
So what is the selected list that we selected?
So the thing is, like this dish types, that's the list where we get the data about the list, so to
speak.
But the dish type, this is the actual name of that list, so to speak.
So that's why we created this extra constant here at the top for our dish types.
Then we created one for the dish categories and so forth, so now we need to add return here for this
and now we need to do the same thing basically for the category as well as the cooking time.
So that's something that I would like you to try for yourself.
So pause the video and try it for yourself.
We can, however, already start the execution here and run the code and see if this is going to work
with our custom items list for the dish types.
OK, so let's go over to our application.
And let's go over here and click on type, and you see it pops up, we have all the different options.
Of course, they are not clickable because we didn't implement it, but we can click on it at the same
time.
We cannot click on category while we can.
But you see, it's not focus all, even though we can try it.
Yeah.
So this is something that we definitely want to change.
So once we click on it, we want to execute something which means we want to do the same thing as we
did here, but with the dish categories so positively.
A real quick try it for yourself, please.
OK, I hope you tried it, so here I have to eat category, which means it's going to be this added
text, of course, which is this category text in the UI that we just saw.
And then we also call this custom items list dialogue method, which will basically just pop up this
little pop up or display this pop up where we set the string to be the title of the dialogue, then
the categories dish list.
So this is the list of categories and then the name of the.
Selection, so to speak, and now the same thing goes for the cooking time, so let's now add that in
here as well.
So now cooking time, same concept.
But here that's to at cooking time, which is basically if you scroll down, it's this part here.
This one.
And.
Here we also call the custom items, this dialogue, we set the title, we set list and we said the
name of the list so we know which list we selected from, so to speak.
OK, that will be relevant later on.
Once we move on with the application right now, it will be relevant, but later on it will be important
to know from which dialogue did we select something.
OK, that will be really important because we don't want the time to be set up for the types, for example.
OK, let's see if the category works.
We see we have all of those categories and you can see this is a recycler view where we can now scroll
because, well, that was also the idea to make it big enough so that we actually have to scroll and
select from a bigger list.
Now, let's do the same thing with the cooking time in minutes, and you see here we have all of those
cooking times included there.
OK, so that's it for this video.
I hope you enjoyed it.
This was a more complicated part and they took a little longer.
But now we used viewer bonding and we used it in combination with a custom dialogue, which then used
also a different approach of using the adapter because we used to be binding, of course.
So really good stuff.
This will help you to move forward in your career with more complex applications.
OK, so see you in the next video.