nephilimrising nephilimrising - 1 year ago 108
Android Question

Understanding android navigation drawer and fragments

i'm quite new to drawer material and i have trouble understanding some things:
I need to create an

with a
on it. Different selections on the
must replace the current
with another one, but is the
something in the fragment or it is one for the activity itself. More specifically is the
living in the
and if not is it possible to create it in the
. I am asking this cause i see that when initiating the
you need to fill parent activity. Also when i tried to use the
Navigation Drawer
template in
Android Studio
i didn't had the
Use a Fragment

Answer Source

There are many ways to achieve what you want. But I think the simplest way is:

1) DrawerLayout view should reside in the activity (probably as the base layout).

2) When you click on an item in the draw 2 things happen:

  • The fragment is replaced (you have one layout to contain the fragment and you just replace the fragment in it).

  • The items inside the drawer update (if you are making a list you would simply set the data and call notifyDataSetChanged().

Don't forget to save your state so it can recover in case the Activity is recreated.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download