kanytu / android-material-drawer-template

An Android template with navigation drawer for material design
Apache License 2.0
674 stars 217 forks source link

How do you change the selected NavigationDrawer Item Selected? #31

Closed surfer190 closed 9 years ago

surfer190 commented 9 years ago

When you change orientation, the activity runs the onCreate again. It also creates/sets up the NavigationDrawerFragment.

So if we have previously selected the 2nd item in the list and change the configuration by changing orientation, the 2nd item will stay as selected. It will also show the relevant fragment for that item (when set up).

However if we change the fragment via a button, on one of the fragments within, and call onNavigationDraweItemSelected manually. The fragment shown will change but the selected item/position in the navigation drawer does not change.

Hence when you rotate, the visible fragment will be based on the selected item that has not changed.

So how can we change the selected item in the Navigation Drawer, from some other method.

surfer190 commented 9 years ago

Use:

private NavigationDrawerFragment mNavigationDrawerFragment;
...
mNavigationDrawerFragment.selectItem(position);