Dynamically change fragment destination in bottom navigation

Viewed 602

I'm using bottom navigation with navigation component architecture. I want to change the first fragment destination dynamically. so I have Fragment1 and Fragment2. I want in some conditions, clicking on the first item in bottom nav open the Fragment1 and in other conditions open Fragment2

1 Answers

You can use something like:

    bottomNavigationView.setOnNavigationItemSelectedListener {
        if (it.itemId == ..){
            //navigate to Fragment1 or Fragment2
            true
        }
        //Trigger the original listener for the other items
        NavigationUI.onNavDestinationSelected(it, navController)
        true
    }
Related