Navigation
object 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 functions |
|
---|---|
const View.OnClickListener |
createNavigateOnClickListener(resId: @IdRes Int!, args: Bundle?) Create an |
const View.OnClickListener |
createNavigateOnClickListener(directions: NavDirections!) Create an |
const NavController |
findNavController(activity: Activity!, viewId: @IdRes Int!) Find a |
const NavController |
findNavController(view: View!) Find a |
const Unit |
setViewNavController(view: View!, controller: NavController?) Associates a NavController with the given View, allowing developers to use |
Public functions
createNavigateOnClickListener
const fun createNavigateOnClickListener(resId: @IdRes Int!, args: Bundle? = null): View.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: @IdRes Int! |
an |
args: Bundle? = null |
arguments to pass to the final destination |
Returns | |
---|---|
View.OnClickListener |
a new click listener for setting on an arbitrary view |
createNavigateOnClickListener
const fun createNavigateOnClickListener(directions: NavDirections!): View.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 |
Returns | |
---|---|
View.OnClickListener |
a new click listener for setting on an arbitrary view |
findNavController
const fun findNavController(activity: Activity!, viewId: @IdRes Int!): NavController
Find a NavController
given the id of a View and its containing Activity
. This is a convenience wrapper around findNavController
.
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: @IdRes Int! |
The id of the view to search from |
Returns | |
---|---|
NavController |
the |
Throws | |
---|---|
kotlin.IllegalStateException |
if the given viewId does not correspond with a |
findNavController
const fun findNavController(view: View!): NavController
Find a NavController
given a local View
.
This method will locate the NavController
associated with this view. This is automatically populated for views that are managed by a NavHost
and is intended for use by various listener
interfaces.
Parameters | |
---|---|
view: View! |
the view to search from |
Returns | |
---|---|
NavController |
the locally scoped |
Throws | |
---|---|
kotlin.IllegalStateException |
if the given view does not correspond with a |
setViewNavController
const fun setViewNavController(view: View!, controller: NavController?): Unit
Associates a NavController with the given View, allowing developers to use findNavController
and findNavController
with that View or any of its children to retrieve the NavController.
This is generally called for you by the hosting NavHost
.
Parameters | |
---|---|
view: View! |
View that should be associated with the given NavController |
controller: NavController? |
The controller you wish to later retrieve via |