Sulav Timsina
Sulav Timsina

Reputation: 843

Navigation drawer Menu list item not updating programmaticaly

I have been working on an Android Project.I have a setting activity, where if i tick an option A, then the navigation drawer should show option A and when I don't tick, it shouldn't. The state of the tick button is saved in shared preferences.

How do I make the navigation drawer to check the value in shared preferences to decide whether to show or not to show the item A?

Upvotes: 1

Views: 126

Answers (1)

Amir Panahandeh
Amir Panahandeh

Reputation: 9029

I'm doing that with two different xml files. In xml files set id for the groups then in your activities onResume remove each groups with this code:

navigationView.getMenu().removeGroup(R.id.first_group);

Then check for the shared preferences tick state and with a if statement do this:

if (tick) {    
    navigationView.inflateMenu(R.menu.drawer_tick);
} else {
    navigationView.inflateMenu(R.menu.drawer_nottick);
}

Upvotes: 1

Related Questions