NavGraph
public class NavGraph extends NavDestination
DynamicGraphNavigator.DynamicNavGraph |
The |
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.
Construct a new NavGraph. This NavGraph is not valid until you add a destination and set the starting destination.
Summary
Nested types |
|
|---|---|
NavGraph.Companion |
|
Public fields |
|
|---|---|
final @NonNull Map<@NonNull String, @NonNull NavArgument> |
The arguments supported by this destination. |
final int |
The destination's unique ID. |
final @Nullable CharSequence |
The descriptive label of this destination. |
final @NonNull String |
The name associated with this destination's |
final @NonNull SparseArrayCompat<@NonNull NavDestination> |
|
final @Nullable NavGraph |
Gets the |
final @Nullable String |
The destination's unique route. |
final @NonNull String |
|
final int |
The starting destination id for this NavGraph. |
final @Nullable String |
The route for the starting destination for this NavGraph. |
Public methods |
|
|---|---|
final void |
Add all destinations from another collection to this one. |
final void |
addDestination(@NonNull NavDestination node)Adds a destination to this NavGraph. |
final void |
addDestinations(@NonNull Collection<@NonNull NavDestination> nodes)Adds multiple destinations to this NavGraph. |
final void |
addDestinations(@NonNull NavDestination nodes)Adds multiple destinations to this NavGraph. |
final void |
clear()Clear all destinations from this navigation graph. |
boolean |
|
final @Nullable NavDestination |
Finds a destination in the collection by ID. |
final @Nullable NavDestination |
Finds a destination in the collection by route. |
final @IdRes int |
This method is deprecated. Use getStartDestinationId instead. |
int |
hashCode() |
final @NonNull Iterator<@NonNull NavDestination> |
iterator() |
void |
onInflate(@NonNull Context context, @NonNull AttributeSet attrs)Called when inflating a destination from a resource. |
final void |
remove(@NonNull NavDestination node)Remove a given destination from this NavGraph |
final void |
setStartDestination(int startDestId)Sets the starting destination for this NavGraph. |
final void |
setStartDestination(@NonNull String startDestRoute)Sets the starting destination for this NavGraph. |
@NonNull String |
toString() |
Inherited methods |
||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||
Public fields
arguments
@NonNull
public final @NonNull Map<@NonNull String, @NonNull NavArgument> arguments
The arguments supported by this destination. Returns a read-only map of argument names to NavArgument objects that can be used to check the type, default value and nullability of the argument.
To add and remove arguments for this NavDestination use addArgument and removeArgument.
id
@NonNull
public final int id
The destination's unique ID. This should be an ID resource generated by the Android resource system.
navigatorName
@NonNull
public final @NonNull String navigatorName
The name associated with this destination's Navigator.
parent
@Nullable
public final @Nullable NavGraph parent
Gets the NavGraph that contains this destination. This will be set when a destination is added to a NavGraph via NavGraph.addDestination.
route
@Nullable
public final @Nullable String route
The destination's unique route. Setting this will also update the id of the destinations so custom destination ids should only be set after setting the route.
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
is the given route is empty |
startDestinationId
@NonNull
public final int startDestinationId
The starting destination id for this NavGraph. When navigating to the NavGraph, the destination represented by this id is the one the user will initially see.
startDestinationRoute
@Nullable
public final @Nullable String startDestinationRoute
The route for the starting destination for this NavGraph. When navigating to the NavGraph, the destination represented by this route is the one the user will initially see.
Public constructors
NavGraph
public final NavGraph(@NonNull Navigator<@NonNull NavGraph> navGraphNavigator)
| Parameters | |
|---|---|
@NonNull Navigator<@NonNull NavGraph> navGraphNavigator |
The |
Public methods
addAll
@NonNull
public final void addAll(@NonNull 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.
addDestination
@NonNull
public final void addDestination(@NonNull NavDestination node)
Adds a destination to this NavGraph. The destination must have an NavDestination.id id} set.
The destination must not have a parent set. If the destination is already part of a navigation graph, call remove before calling this method.
| Parameters | |
|---|---|
@NonNull NavDestination node |
destination to add |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if destination does not have an id, the destination has the same id as the graph, or the destination already has a parent. |
addDestinations
@NonNull
public final void addDestinations(@NonNull Collection<@NonNull NavDestination> nodes)
Adds multiple destinations to this NavGraph. Each destination must have an NavDestination.id id} set.
Each destination must not have a parent set. If any destination is already part of a navigation graph, call remove before calling this method.
| Parameters | |
|---|---|
@NonNull Collection<@NonNull NavDestination> nodes |
destinations to add |
addDestinations
@NonNull
public final void addDestinations(@NonNull NavDestination nodes)
Adds multiple destinations to this NavGraph. Each destination must have an NavDestination.id id} set.
Each destination must not have a parent set. If any destination is already part of a navigation graph, call remove before calling this method.
| Parameters | |
|---|---|
@NonNull NavDestination nodes |
destinations to add |
findNode
@Nullable
public final NavDestination findNode(@IdRes 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 | |
|---|---|
@IdRes int resId |
ID to locate |
| Returns | |
|---|---|
NavDestination |
the node with ID resId |
findNode
@Nullable
public final NavDestination findNode(@Nullable String route)
Finds a destination in the collection by route. This will recursively check the parent of this navigation graph if node is not found in this navigation graph.
| Returns | |
|---|---|
NavDestination |
the node with route |
getStartDestination
@IdRes
@NonNull
public final @IdRes intgetStartDestination()
Gets the starting destination for this NavGraph. When navigating to the NavGraph, this destination is the one the user will initially see.
| Returns | |
|---|---|
@IdRes int |
the start destination |
iterator
@NonNull
public final Iterator<@NonNull NavDestination> iterator()
| Throws | |
|---|---|
kotlin.NoSuchElementException |
if there no more elements |
onInflate
@NonNull
public void onInflate(@NonNull Context context, @NonNull AttributeSet attrs)
Called when inflating a destination from a resource.
| Parameters | |
|---|---|
@NonNull Context context |
local context performing inflation |
@NonNull AttributeSet attrs |
attrs to parse during inflation |
remove
@NonNull
public final void remove(@NonNull NavDestination node)
Remove a given destination from this NavGraph
| Parameters | |
|---|---|
@NonNull NavDestination node |
the destination to remove. |
setStartDestination
@NonNull
public final void setStartDestination(int startDestId)
Sets the starting destination for this NavGraph.
This will clear any previously set startDestinationRoute.
| Parameters | |
|---|---|
int startDestId |
The id of the destination to be shown when navigating to this NavGraph. |
setStartDestination
@NonNull
public final void setStartDestination(@NonNull String startDestRoute)
Sets the starting destination for this NavGraph.
This will override any previously set startDestinationId