Hello. I have a list of categories loaded from the server. When I launch a fragment (I make a click from the menu), the menu item is marked as active and a certain fragment is loaded. But if you turn the screen and open the menu, you can see that the item of the current fragment is not marked as active. In the onCreate (...) method of the fragment, I check item's emptiness, I see entries in the log about the existence of categories. Then I write the following:

navigation.getMenu().getItem(cat_id).setChecked(true).setCheckable(true) 

But the item is still not marked. Please give direction

    1 answer 1

    Your code needs to be called after the NavigationDrawer has uninstalled, but it does not always work. Try:

     onNavigationItemSelected(navigationView.getMenu().findItem(R.id.nav_profile)); 
    • Well, so I do, it still does not work. - sergei1094
    • If onCreate () I can already find out the list and number of my items, it means that NavigationDrawer is injected, right? Or what do you mean? What does it mean but it doesn't always work? - sergei1094
    • You used onNavigationItemSelected (navigationView.getMenu (). FindItem (R.id.nav_profile)); -? and does not work? - Eugene Zaychenko