Description:
OnNavigationItemSelectedListener listener is not called when i select any tab in bottomNavigationView
`
private void setupBottomNavigation(NavController navController) {
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.search_dest) {
Log.d(TAG, "onNavigationItemSelected: search fragment");
} else {
Log.d(TAG, "onNavigationItemSelected: default fragment");
}
return true;
}
`});`
NavigationUI.setupWithNavController(bottomNavigationView, navController);
}``
currently I'm using 'com.google.android.material:material:1.2.0-alpha05'
seems NavigationUI replaces the lisitener you are setting. Since this is outside our library. Maybe report a bug with them.
@Robotecom I ran into a similar issue. You might have already solved this, but I solved it as follows:
Instead of returning true from your OnNavigationItemSelectedListener return NavigationUI.onNavDestinationSelected(item, navController).
Also, call setupWithNavController before adding your listener.
Most helpful comment
@Robotecom I ran into a similar issue. You might have already solved this, but I solved it as follows:
Instead of returning
truefrom yourOnNavigationItemSelectedListenerreturnNavigationUI.onNavDestinationSelected(item, navController).Also, call
setupWithNavControllerbefore adding your listener.