Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Navigation drawer listview

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.

like image 610
Nicholas Mata Avatar asked Jul 06 '14 11:07

Nicholas Mata


1 Answers

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());
}
like image 167
David Ferrand Avatar answered Sep 28 '22 03:09

David Ferrand