Welcome back.
And this video, we are going to check out how to move from one fragment to another because we are in
the all dishes fragment and we are going to move over to this.
The details fragment once we click on one of those dishes for now.
We are not going to design this screen.
We're going to design that later.
But for now, we're really going to focus on how to move from one fragment to another.
And, of course, then display the right details later on.
So the first thing that we are going to require for this is going to be a new fragment.
OK, so let's go ahead and go over to our fragments here and let's create a new fragments, which will
be a blank fragment here.
And I'm going to call this one dish details fragment.
All right, so for now, what I want to do in here, I'm going to go over and go to the fragment details
and centered the text for now.
OK, so let's add gravity to it, gravity and set it to center.
This will make sure that the text will be in the middle.
OK, and then we can, of course, also change the text.
So for now, I'm just going to change that to.
I hardcoded Valge details, fragrantly.
We're going to change that anyways.
We're going to get rid of this whole thing anyways, right?
So the next thing will be to clean up a little bit because, well, we have a lot of stuff in here which
we don't even need.
OK, so let's clean up this fragment.
So first of all, we won't need those programs here and let's get rid of those as well.
And accordingly, and uncreate view, well, everything should be fine so far, this companion object
has a nice idea, but we're not going to need it as of now.
And if we need it, then we will create it.
Now, let's go over to Mobile Navigation XML.
And here we see all the three fragments that we had so far.
Now I will add a new fragment in here.
So let me go ahead and create that in here, which will basically be our details.
So this details fragment and it will be EHU tutorials.
And the details fragment, this one here at the top.
And in terms of the.
Title here, let's create a new string entry.
Therefore, we're going to go over to the strings smell, just going to add a new one here, Hidell
dish soap, the sort of blank fragment.
Let me get rid of that as well.
So dish details is how I'm going to call that.
Let's go back to this file and I'm going to use this for the label.
I know, let's add something that we haven't added so far, and that is a navigation.
From one.
Fragment to another.
OK, so here we have our different fragments, the navigation favorite and all dishes.
And what I want is I want to be moving from.
This year, this fragment, the navigation, all dishes over to the dish details.
OK, so this will add this little action here.
And if you go into the code, you will find the inside of the fragment, navigation, all dishes and
you action has been created and it even gets a defined I.D. automatically.
You can also give this your own I.D. I'm going to call this one action all dishes to dish details.
And then the destination will be our navigation dish details, which is basically this other fragment
here, this one here that we just created.
And the next thing that we all need to set up is to use safe arcs to pass data with type safety.
OK, so if you want to pass data from one.
Fragment to another.
We need to do it in a type safe way, and in order to do that, one of the best ways is to add the following
line.
So, first of all, we're going to need to add this here inside of our build that gradle file.
So let's go over there.
Projects and here all the way down and the gradle projects are in the file and they there, we can either
apply the plug in or we can also do the following.
So you can go to the IDC or plug ins here at the very top and at this one here.
So this will also apply to plugin, which will be the safe ARC's Scotland plugin.
And then we need to go to the other build dot gradle, which is the project Bellport Gradle.
And here we're going to add and here instead of dependencies, let's add a new entry which will be using
to the reader as a navigation version.
And this will be the class path here.
So Android Akst Navigation, Navigation, Safe, Herkes Gradle plugin, which is what you can see here,
even though, well, here the version has changed to two, three, three.
So we can also use two, three, three at that point.
So that will be the navigation version that we're going to use with this plugin.
Once I'm done with that, make sure that you think both files.
OK, so this one, as well as the app builder Gradle and it sinks it for me, Gradle Sync is in process.
All right.
That's good.
Now, after enabling safe args, you're generated code contains the following types of classes and methods
for each action, as well as with each sending and receiving destination.
So a class is created for each destination where an action originates.
OK, so in our case the action originates from our fragment navigation.
All dishes here.
This is the action, OK, at this class as a method for each action you find in the originating destination,
for each action used to pass the argument and in class as created, whose name is based on the action.
For example, if the action is called conformation action, the class is named conformation action.
If you action contains arguments without a default value, then use the associated action class to set
the value of the argument.
And by the way, this should create a new file here inside of our Jumma generated, so here.
There should be one that is not the model, as you can see, this is the model database that was created
for us and not to build conflict, but there should be one for fragments.
And in my case, it didn't.
So I'm going to clean a project.
And I'm going to rebuild the project.
And then I had to go to my builder Gradle at once again and get rid of this line, sink it and add the
line again to sink it again.
So, yeah, it's important that you maintain this order.
So now, in my case, I can see the fragments and you can see here.
So it's in Java generate.
You can see this file was generated for us.
All dishes fragment directions which will take the action for us or create the action for us to move
from one screen to another.
So from one fragment to another.
Now, what I want to do is inside of all dishes fragment.
I want to.
We get a new function, which I'm going to call the details, OK, you could call it go to dish details
or something like that, but I'm going to find NAV controller here to navigate to our all dishes, fragment
directions, dot action, all dishes to details.
OK, so this function will now navigate to this action that we created.
Where does this action come from?
Well, if you look at the XML file, this mobile you can see here, that's the action action, all dishes
to dish details.
OK, that's the action that we created.
And now the class created the method for us, which will then take care of us moving from one screen
or one fragment to another.
Now, at one point, we will need to call this and I want to call it once I click on the item.
So once I click on any of my items here.
And where would I handle that?
Well, in the five dish adapter, OK, so here we have our unbind view holder, that is where we need
to define the unclick event.
So here I'm going to say holder dot item view.
That set on Click Listener and I will check if the fragment is an audacious fragment.
Then I will call fragment dot dish details, which is this method that we just created.
OK, so which is this method here which will then navigate to this other screen, which is the action
that we created.
So here this action here, which we basically have dragged here earlier on.
So let's see if this is going to work for us, so let's move from one fracking to another.
All right, so there we are.
Let's click on it and see if we can move over to the other screen.
And this is our dish details activity.
Does beg pardon, however, is not implemented, so we can't really move over to the other activity
unless we click the back button here.
OK, so that's something that we are going to take care of later on.
But for now, you see, we can move from one fragment to another using this advanced white.