Tah*_*ami 0 android android-fragments android-architecture-navigation
我的应用程序从NewAdFragment这个片段开始,里面有一个按钮,允许用户选择类别,当用户单击该按钮时,我将通过ChooserFragment传递类别列表作为参数将他导航到,这个片段中有 RecyclerView ,它显示类别。
我想要什么?我希望当用户从 RecyclerView 中选择一个项目时,它必须返回NewAdFragment特定的数据。
我可以用很多方法解决这个问题,但也许导航组件库中已经存在一种方法。
最好的方法是什么?
尝试实现下面提到的代码块:
片段A
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val navController = findNavController();
// We use a String here, but any type that can be put in a Bundle is supported
navController.currentBackStackEntry?.savedStateHandle?.getLiveData<String>("key")?.observe(
viewLifecycleOwner) { result ->
// Do something with the result.
}
}
Run Code Online (Sandbox Code Playgroud)
片段B
navController.previousBackStackEntry?.savedStateHandle?.set("key", result)
navController.popBackStack()
Run Code Online (Sandbox Code Playgroud)
你也可以检查这个
| 归档时间: |
|
| 查看次数: |
4315 次 |
| 最近记录: |