Update Navigation drawer listview
Asked Answered
E

1

10

My application implements a navigation drawer to change fragments. What I need now is to update the navigation drawer items if the user is logged in

For example : logged in navigation items look like this

Home My Info Logout

logged off navigation items look like this

Home Register Login

The set up of my project is a Base activity which extends Navigation fragment and changes to a current fragment based on the selected navigation drawer item.

All my other files are fragments which change depending on the navigation drawer item selected.

I have this kind of working but navgation drawer only updates when I log in then close the app completely and then re start it.

Epileptoid answered 6/7, 2014 at 11:18 Comment(0)
P
17

Your Activity must be aware of your drawer's ListView. So when you log in, you just need to tell your Activity to tell your ListView that the data has changed, or reload it completely.

In your fragment (or wherever you actually log in):

public void logIn() {
    ...
    ((DrawerActivity) getActivity()).updateDrawer();
}

In your DrawerActivity:

public void updateDrawer() {
    mListViewAdapter.notifyDataSetChanged();
    // OR
    mListView.setAdapter(new AdapterShowingTheRightTitles());
}
Parados answered 7/7, 2014 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.