I'm trying to make a navigation using NavigationUI as in this tutorial video. Below is code for my activity:
BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
NavController navController = navHostFragment.getNavController();
AppBarConfiguration appBarConfiguration = new AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.dashboardMerchant, R.id.listMenuMerchant, R.id.addMenuMerchant).build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(bottomNavigationView, navController);
My question is how to pass data from my activity to firstFragment
or between framents. I already read this tutorial to pass bundle object, but I didn't know where to put the passing code in my activity or fragment.
Any idea how to do this?
Below is the XML file of my_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/merchant_navigation"
app:startDestination="@id/listMenuMerchant">
<fragment
android:id="@+id/listMenuMerchant"
android:name="com.example.fooddelivery.ListMenuMerchant"
android:label="List Menu"
tools:layout="@layout/fragment_list_menu">
<argument
android:name="user_info_string"
app:argType="string"
android:defaultValue=""/>
</fragment>
<fragment
android:id="@+id/addMenuMerchant"
android:name="com.example.fooddelivery.AddMenuMerchant"
android:label="Add Menu"
tools:layout="@layout/fragment_add_menu">
<argument
android:name="user_info_string"
app:argType="string"
android:defaultValue=""/>
</fragment>
<fragment
android:id="@+id/dashboardMerchant"
android:name="com.example.fooddelivery.DashboardMerchant"
android:label="Dashboard"
tools:layout="@layout/fragment_dashboard_merchant">
<argument
android:name="user_info_string"
app:argType="string"
android:defaultValue=""/>
</fragment>
</navigation>