I am using the navigation component to load my fragments like given here: 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)
I also have a Toolbar
at the top with a Spinner. I want to reload/refresh the fragment
& its view model when the spinner
item is selected. I tried the below code for reloading but it isn't working. Also, I know we should not be using fragmentManager
in Navigation Component
val ftr: FragmentTransaction = requireFragmentManager().beginTransaction()
ftr.detach(this).attach(this).commit()
Any help would be appreciated.