Reputation: 7621
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
Upvotes: 3
Views: 856
Reputation: 175
bottomNavigationView.setOnItemSelectedListener{ item ->
when (item.itemId) {
R.id.firstItem -> {
if(condition){
navController.navigate(fragment1)
}else{
navController.navigate(fragment2)
}
}
}
}
Upvotes: 1
Reputation: 363479
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
}
Upvotes: 4