[英]In Android Navigation Architecture, how can I call one of destination fragments' methods from the host (activity)
I use Navigation Architecture in my project and I have some fragments as destinations. 我在项目中使用了导航架构,并且有一些片段作为目标。 Its host is my MainActivity. 它的主人是我的MainActivity。 Now I want to call one of my destinations' methods from the host (MainActivity). 现在,我想从主机(MainActivity)调用目标的方法之一。 What should I do? 我该怎么办?
You need to get the navController and then call the destination fragment by action I'd or destination I'd as defined in your navigationgraph.xml 您需要获取navController,然后通过您的navigationgraph.xml中定义的操作或目标调用目标片段
Refer Android doc for navigating to destination section: https://developer.android.com/guide/navigation/navigation-getting-started#java 请参阅Android文档以导航到目标部分: https : //developer.android.com/guide/navigation/navigation-getting-started#java
//Sample code //示例代码
Navigation.findNavController(view).navigate(R.id.viewTransactionsAction); Navigation.findNavController(view).navigate(R.id.viewTransactionsAction);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.