Tnoff Apps
Tnoff Apps

Reputation: 47

Android: Changing selected menu item

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

Answers (1)

RaBaKa 78
RaBaKa 78

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

Related Questions