1

my image

Hello guys I use templater Bottom Navigation Activity and dont know how to scroll to top RecyclerView in my Home Fragment

My MainActivity code:

AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
            R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
            .build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
    NavigationUI.setupWithNavController(navView, navController);
fdai31.5
  • 11
  • 1

1 Answers1

1

The question is quit old, but maybe it helps others. This is the code you have to put in the fragment (in Kotlin):

val nav = activity?.findViewById<BottomNavigationView>(R.id.bottom_navigation)
nav?.setOnItemReselectedListener { item ->
    if (item.itemId == R.id.mainFragment) {
        recyclerView.smoothScrollToPosition(position)
    }
}
Jannis
  • 11
  • 2