NavGraph
public
class
NavGraph
extends NavDestination
implements
Iterable<NavDestination>
java.lang.Object | ||
↳ | 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 | |
---|---|
NavGraph(Navigator<? extends NavGraph> navGraphNavigator)
Construct a new NavGraph. |
Public methods | |
---|---|
final
void
|
addAll(NavGraph other)
Add all destinations from another collection to this one. |
final
void
|
addDestination(NavDestination node)
Adds a destination to this NavGraph. |
final
void
|
addDestinations(Collection<NavDestination> nodes)
Adds multiple destinations to this NavGraph. |
final
void
|
addDestinations(NavDestination... nodes)
Adds multiple destinations to this NavGraph. |
final
void
|
clear()
Clear all destinations from this navigation graph. |
final
NavDestination
|
findNode(int resid)
Finds a destination in the collection by ID. |
final
int
|
getStartDestination()
Returns the starting destination for this NavGraph. |
final
Iterator<NavDestination>
|
iterator()
|
void
|
onInflate(Context context, AttributeSet attrs)
Called when inflating a destination from a resource. |
final
void
|
remove(NavDestination node)
Remove a given destination from this NavGraph |
final
void
|
setStartDestination(int startDestId)
Sets the starting destination for this NavGraph. |
String
|
toString()
|
Inherited methods | |
---|---|
Public constructors
NavGraph
public NavGraph (Navigator<? extends NavGraph> navGraphNavigator)
Construct a new NavGraph. This NavGraph is not valid until you
add a destination
and
set the starting destination
.
Parameters | |
---|---|
navGraphNavigator |
Navigator : The NavGraphNavigator which this destination
will be associated with. Generally retrieved via a
NavController 's
NavigatorProvider.getNavigator(Class) method.
|
Public methods
addAll
public final void addAll (NavGraph other)
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
public final void addDestination (NavDestination node)
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
public final void addDestinations (Collection<NavDestination> nodes)
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 |
Collection : destinations to add
|
addDestinations
public final void addDestinations (NavDestination... nodes)
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
|
clear
public final void clear ()
Clear all destinations from this navigation graph.
findNode
public final NavDestination findNode (int resid)
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 |
Returns | |
---|---|
NavDestination |
the node with ID resid |
getStartDestination
public final int getStartDestination ()
Returns the starting destination for this NavGraph. When navigating to the NavGraph, this destination is the one the user will initially see.
Returns | |
---|---|
int |
onInflate
public void onInflate (Context context, AttributeSet attrs)
Called when inflating a destination from a resource.
Parameters | |
---|---|
context |
Context : local context performing inflation |
attrs |
AttributeSet : attrs to parse during inflation
|
remove
public final void remove (NavDestination node)
Remove a given destination from this NavGraph
Parameters | |
---|---|
node |
NavDestination : the destination to remove.
|
setStartDestination
public final void setStartDestination (int startDestId)
Sets the starting destination for this NavGraph.
Parameters | |
---|---|
startDestId |
int : The id of the destination to be shown when navigating to this NavGraph.
|
toString
public String toString ()
Returns | |
---|---|
String |