0

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.

Tnoff Apps
  • 37
  • 6

1 Answers1

1

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.

RaBaKa 78
  • 1,115
  • 7
  • 11
  • Ok, thank you. But when I take away the view in front of findViewById, I am getting this: `cannot resolve method 'findViewById' in 'UsersFragment'` – Tnoff Apps Oct 23 '21 at 15:36
  • https://stackoverflow.com/questions/6495898/findviewbyid-in-fragment explained here. – RaBaKa 78 Oct 24 '21 at 20:40