4

I have an activity with BottomNavigationView with 5 items and fragment to show the pages, I set the NavController as following : NavigationUI.setupWithNavController(mBottomNavigationView, navController);

but there is one item in the bottom navigation in some Scenario will open another activity.

I tried to add setOnNavigationItemSelectedListener and handle it but, the navigation for the other items doesn't work.

can anyone help me ?

1 Answers1

7

Instead of setOnNavigationItemSelectedListener use addOnDestinationChangedListener. navController.addOnDestinationChangedListener((controller, destination, arguments) -> { if(destination.getId()==R.id.menu_item_id){ //navigate to other activity } });

Rahul
  • 481
  • 4
  • 9