‫Hello, my friends.
‫In this video we will talk about the nav controller.
‫Navigating to the destination is done using a nav controller, an object that manages app navigation
‫within a nav host.
‫Each nav host has its own corresponding nav controller.
‫You can retrieve a nav controller by using one of the following methods.
‫The fragment dot find nav controller view dot find nav controller activity dot find nav controller and
‫we pass the view ID as integer parameter.
‫Actions.
‫The roots user can take between your app's destination is called actions.
‫Which are represented by the Arrow sign in the design view.
‫Let's jump into Android studio and start using the nav controller and see the actions.
‫In the nav navigation editor.
‫To create an action between the home fragment and the second fragment.
‫It's very simple to drag and drop this.
‫You can see this arrow will represent an action.
‫If I click it, you can see the attributes.
‫Here and its ID is called action from fragment to second fragment.
‫And the destination is the second fragment.
‫Here, the action is telling us that its ID is this and we're going from home fragment to the destination,
‫which is the second fragment.
‫If I go to the nav graph, we go to the split mode and we can see that the fragments, the two fragments
‫that we've created are here and we can see the action.
‫Attribute or tag here.
‫And the ID is this.
‫The app destination is the second fragment.
‫This action is for the home of fragment, which tells us that, hey, I'm going from this fragment.
‫Home fragment to the destination.
‫The second fragment.
‫Now in order to set a click event to this button and allow this action to take take place, we need
‫to go to the home of Fragment.
‫And here in the Oncreate view, I need to set the binding before returning the binding dot route I need
‫to handling to handle the click event on the button.
‫So I will use the data binding library to find the button dot submit dot set on click listener and here
‫I need.
‫Do get.
‫This is the view.
‫It's of type view it dot find nav controller.
‫This is the method that I was talking about.
‫Dot navigate.
‫And here I will pass the r.id dot action.
‫Homo fragment.
‫The second fragment.
‫Here I am telling Android studio.
‫Whenever we click on this button, the submit button, go and do the action, which is called which
‫ID is action Homo fragment.
‫Second fragment.
‫So go and execute this action in the navigation.
‫Let's run our application and see how things will work in.
‫Okay, here we go.
‫This is our application.
‫If I click on submit, it will give me and it will direct me to the second fragment.
‫There we go.
‫This is our application.
‫If I click submit, it will give me or will direct me to the second fragment.
‫So congratulations, guys.
‫We've learned about the navigation, the navigation controller, the nav graph and the destinations.
‫In the next videos, we'll learn how to pass data between the fragments, the destinations, and we
‫will learn more and more about navigation architecture.