NavGraph
open class NavGraph : NavDestination, MutableIterable<NavDestination!>
kotlin.Any | ||
↳ | androidx.navigation.NavDestination | |
↳ | androidx.navigation.NavGraph |
NavGraph is a collection of NavDestination
nodes fetchable by ID.
A NavGraph serves as a 'virtual' destination: while the NavGraph itself will not appear on the back stack, navigating to the NavGraph will cause the starting destination
to be added to the back stack.
Summary
Public constructors |
|
---|---|
Construct a new NavGraph. |
Public methods |
|
---|---|
Unit |
Add all destinations from another collection to this one. |
Unit |
addDestination(@NonNull : NavDestination) Adds a destination to this NavGraph. |
Unit |
addDestinations(@NonNull : MutableCollection<NavDestination!>) Adds multiple destinations to this NavGraph. |
Unit |
addDestinations(@NonNull vararg : NavDestination!) Adds multiple destinations to this NavGraph. |
Unit |
clear() Clear all destinations from this navigation graph. |
NavDestination? |
Finds a destination in the collection by ID. |
Int |
Returns the starting destination for this NavGraph. |
MutableIterator<NavDestination!> |
iterator() |
open Unit |
onInflate(@NonNull : Context, @NonNull : AttributeSet) |
Unit |
remove(@NonNull : NavDestination) Remove a given destination from this NavGraph |
Unit |
setStartDestination(@IdRes : Int) Sets the starting destination for this NavGraph. |
open String |
toString() |
Inherited functions |
|
---|---|
Extension functions |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|
From androidx.navigation
|
Public constructors
<init>
NavGraph(@NonNull : Navigator<out NavGraph!>)
Construct a new NavGraph. This NavGraph is not valid until you add a destination
and set the starting destination
.
Parameters | |
---|---|
navGraphNavigator |
Navigator<out NavGraph!>: The NavGraphNavigator which this destination will be associated with. Generally retrieved via a NavController 's NavigatorProvider#getNavigator(Class) method. |
Public methods
addAll
fun addAll(@NonNull : NavGraph): Unit
Add all destinations from another collection to this one. As each destination has at most one parent, the destinations will be removed from the given NavGraph.
Parameters | |
---|---|
other |
NavGraph: collection of destinations to add. All destinations will be removed from this graph after being added to this graph. |
addDestination
fun addDestination(@NonNull : NavDestination): Unit
Adds a destination to this NavGraph. The destination must have an NavDestination#getId()
id} set.
The destination must not have a parent
set. If the destination is already part of a navigation graph
, call remove(NavDestination)
before calling this method.
Parameters | |
---|---|
node |
NavDestination: destination to add |
addDestinations
fun addDestinations(@NonNull : MutableCollection<NavDestination!>): Unit
Adds multiple destinations to this NavGraph. Each destination must have an NavDestination#getId()
id} set.
Each destination must not have a parent
set. If any destination is already part of a navigation graph
, call remove(NavDestination)
before calling this method.
Parameters | |
---|---|
nodes |
MutableCollection<NavDestination!>: destinations to add |
addDestinations
fun addDestinations(@NonNull vararg : NavDestination!): Unit
Adds multiple destinations to this NavGraph. Each destination must have an NavDestination#getId()
id} set.
Each destination must not have a parent
set. If any destination is already part of a navigation graph
, call remove(NavDestination)
before calling this method.
Parameters | |
---|---|
nodes |
NavDestination!: destinations to add |
findNode
@Nullable fun findNode(@IdRes : Int): NavDestination?
Finds a destination in the collection by ID. This will recursively check the parent
of this navigation graph if node is not found in this navigation graph.
Parameters | |
---|---|
resid |
Int: ID to locate |
Return | |
---|---|
NavDestination?: the node with ID resid |
getStartDestination
@IdRes fun getStartDestination(): Int
Returns the starting destination for this NavGraph. When navigating to the NavGraph, this destination is the one the user will initially see.
Return | |
---|---|
Int: |
iterator
@NonNull fun iterator(): MutableIterator<NavDestination!>
onInflate
open fun onInflate(@NonNull : Context, @NonNull : AttributeSet): Unit
remove
fun remove(@NonNull : NavDestination): Unit
Remove a given destination from this NavGraph
Parameters | |
---|---|
node |
NavDestination: the destination to remove. |
setStartDestination
fun setStartDestination(@IdRes : Int): Unit
Sets the starting destination for this NavGraph.
Parameters | |
---|---|
startDestId |
Int: The id of the destination to be shown when navigating to this NavGraph. |
toString
@NonNull open fun toString(): String