我正在使用导航组件加载我的片段,如下所示:https : //developer.android.com/guide/navigation/navigation-getting-started
navController = findNavController(R.id.nav_host_fragment)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.navigation_opt1,
R.id.navigation_opt2,
R.id.navigation_opt3,
R.id.navigation_more
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
Run Code Online (Sandbox Code Playgroud)
我Toolbar在顶部也有一个 Spinner。我想在选择项目fragment时重新加载/刷新& 它的视图模型spinner。我尝试了以下代码进行重新加载,但它不起作用。另外,我知道我们不应该fragmentManager在导航组件中使用
val ftr: FragmentTransaction = requireFragmentManager().beginTransaction()
ftr.detach(this).attach(this).commit()
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
android android-fragments kotlin android-architecture-navigation