Navigation
class Navigation
kotlin.Any | |
↳ | androidx.navigation.Navigation |
Entry point for navigation operations.
This class provides utilities for finding a relevant NavController
instance from various common places in your application, or for performing navigation in response to UI events.
Summary
Public methods | |
---|---|
static OnClickListener |
createNavigateOnClickListener(@IdRes : Int) Create an |
static OnClickListener |
createNavigateOnClickListener(@IdRes : Int, @Nullable : Bundle?) Create an |
static OnClickListener |
createNavigateOnClickListener(@NonNull : NavDirections) Create an |
static NavController |
findNavController(@NonNull : Activity, @IdRes : Int) Find a |
static NavController |
findNavController(@NonNull : View) Find a |
static Unit |
setViewNavController(@NonNull : View, @Nullable : NavController?) Associates a NavController with the given View, allowing developers to use |
Public methods
createNavigateOnClickListener
@NonNull static fun createNavigateOnClickListener(@IdRes : Int): OnClickListener
Create an android.view.View.OnClickListener
for navigating to a destination. This supports both navigating via an action
and directly navigating to a destination.
Parameters | |
---|---|
resId |
Int: an action id or a destination id to navigate to when the view is clicked |
Return | |
---|---|
OnClickListener |
a new click listener for setting on an arbitrary view |
createNavigateOnClickListener
@NonNull static fun createNavigateOnClickListener(
@IdRes : Int,
@Nullable : Bundle?
): OnClickListener
Create an android.view.View.OnClickListener
for navigating to a destination. This supports both navigating via an action
and directly navigating to a destination.
Parameters | |
---|---|
resId |
Int: an action id or a destination id to navigate to when the view is clicked |
args |
Bundle?: arguments to pass to the final destination |
Return | |
---|---|
OnClickListener |
a new click listener for setting on an arbitrary view |
createNavigateOnClickListener
@NonNull static fun createNavigateOnClickListener(@NonNull : NavDirections): OnClickListener
Create an android.view.View.OnClickListener
for navigating to a destination via a generated NavDirections
.
Parameters | |
---|---|
directions |
NavDirections: directions that describe this navigation operation |
Return | |
---|---|
OnClickListener |
a new click listener for setting on an arbitrary view |
findNavController
@NonNull static fun findNavController(
@NonNull : Activity,
@IdRes : Int
): NavController
Find a NavController
given the id of a View and its containing Activity
. This is a convenience wrapper around findNavController(View)
.
This method will locate the NavController
associated with this view. This is automatically populated for the id of a NavHost
and its children.
Parameters | |
---|---|
activity |
Activity: The Activity hosting the view |
viewId |
Int: The id of the view to search from |
Return | |
---|---|
NavController |
the NavController associated with the view referenced by id |
Exceptions | |
---|---|
IllegalStateException |
if the given viewId does not correspond with a NavHost or is not within a NavHost. |
findNavController
@NonNull static fun findNavController(@NonNull : View): NavControll