Material-components-android: setOnNavigationItemSelectedListener of BottomNavigationView is not triggered?!

Created on 10 Mar 2020  路  2Comments  路  Source: material-components/material-components-android

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'

bug

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 true from your OnNavigationItemSelectedListener return NavigationUI.onNavDestinationSelected(item, navController).

Also, call setupWithNavController before adding your listener.

All 2 comments

seems NavigationUI replaces the lisitener you are setting. Since this is outside our library. Maybe report a bug with them.

https://issuetracker.google.com/issues/new?component=409828

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KelvinPac picture KelvinPac  路  3Comments

TdevM picture TdevM  路  3Comments

jaychang0917 picture jaychang0917  路  3Comments

magnusfernandes picture magnusfernandes  路  3Comments

Mirmuhsin picture Mirmuhsin  路  3Comments