How can I add startDestination
programmatically according the value for example if the integer variable was 0 then I want to start navigation_main_countries_fragment
, Otherwise navigation_main_categories_fragment
.
Inside activity_main
<androidx.fragment.app.FragmentContainerView
android:id="@+id/activity_main_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:navGraph="@navigation/navigation_main" //I deleted this line already
android:layout_weight="1" />
Inside navigation_main
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/navigation_main_countries_fragment" //I deleted this line already
tools:ignore="InvalidNavigation">
<fragment
android:id="@+id/navigation_main_countries_fragment"
android:name="com.test.app.fragments.CountriesFragment"
tools:layout="@layout/fragment_countries" />
<fragment
android:id="@+id/navigation_main_categories_fragment"
android:name="com.test.app.fragments.CategoriesFragment"
tools:layout="@layout/fragment_categories" />
</navigation>