Reputation: 47
I am trying to change the selected menu item of a BottomNavigationView from a seperate fragment from the one that I initialize the BottomNavigationView in. I am using
MenuItem item = navigationView.getMenu().findItem(R.id.nav_home);
item.setChecked(true);
The problem is that the navigationView is null because I am in a seperate fragment.
I am using
navigationView = view.findViewById(R.id.navigation);
to get the id of the navigationView.
Upvotes: 0
Views: 235
Reputation: 1435
here when you use view.findViewById(R.id.navigation);
, the view
is representing the view
of that separate fragment, which doesn't have such a view , hence it will return null.
Upvotes: 1