Skip to content

Instantly share code, notes, and snippets.

@PaulProject
Last active August 29, 2018 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulProject/2a83c3273ad1253bc0024872e8ce7395 to your computer and use it in GitHub Desktop.
Save PaulProject/2a83c3273ad1253bc0024872e8ce7395 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/main_nav_graph" />
</android.support.constraint.ConstraintLayout>
... some code
NavHostFragment.findNavController(this)
.navigate(R.id.action_carListFragment_to_carFragment)
... some code
<?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"
android:id="@+id/cars_nav_graph"
app:startDestination="@id/carListFragment">
<fragment
android:id="@+id/carListFragment"
android:name="com.example.car.CarListFragment"
android:label="CarListFragment">
<action
android:id="@+id/action_carListFragment_to_carFragment"
app:destination="@id/carFragment" />
</fragment>
<fragment
android:id="@+id/carFragment"
android:name="com.example.car.CarFragment"
android:label="CarFragment" />
</navigation>
<?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/nav_graph"
app:startDestination="@id/mainFragment">
<fragment
android:id="@+id/mainFragment"
android:name="com.example.main.MainFragment"
android:label="MainFragment"
tools:layout="@layout/fragment_main">
<action
android:id="@+id/action_mainFragment_to_cars_nav_graph"
app:destination="@id/cars_nav_graph" />
</fragment>
<include app:graph="@navigation/cars_nav_graph" />
</navigation>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment