4

I have an existing application that has about 25 activities that are navigated to from a "dashboard". I would like to switch and start using the Navigation drawer and fragments. I have gone thru the Nav Drawer design pages online and the example app. My question is what is the best way to convert (structure) my app to fit the Nav Drawer pattern. If I switch my activities to be fragments and use a main activity to replace each fragment as navigation happens, but not sure if that is good b/c for a tablet layout, I might want multiple fragments on my view and not sure if this will limit me. If I go with the other direction I was thinking, keep all my activities and just switch the necessary ones to fragments for tablets but I would need each activity to create the navigation drawer (I think ?) which in my case the drawer is dynamic based on server data. Any suggestions would be great.

Thanks Brandon

Brandon
  • 83
  • 1
  • 5

1 Answers1

0

Navigation drawer has to be created for each activity, although you could inherit Activity and create a parent class that handles navigation drawer specific code if code duplication is a concern.

Using a drawer does not limit you to use one fragment per screen, just listen to onClick in drawer and initiate as many fragment transactions as you need.

When it comes to structuring your app, there is no universal advice, I would recommend you to watch Google I/O 2013 talk - Structure in Android App Design. Navigation Drawer is kind of the main theme of the talk.

Martin
  • 1,877
  • 5
  • 21
  • 37
  • 1
    How do you add the drawer layout while still adding the activities layout? – Maxrunner Jul 21 '13 at 23:19
  • Basically you have 'android.support.v4.widget.DrawerLayout' as a root element with two children first of which has to be the container of your main content, the second one is the container for your navigation drawer. Make sure you set appropriate ids for those containers and reference them properly in your activity. I suggest to read the official documentation here: [Creating a Navigation Drawer](http://developer.android.com/training/implementing-navigation/nav-drawer.html) – Martin Aug 09 '13 at 11:30
  • @malymato this doesn't solve @Maxrunner problem. In the super `DrawerActivity` you will still have to inflate a layout containing the drawer, but you don't know the layout of the sub activities yet. – Michael Sep 09 '13 at 08:22
  • Yes, how do we add the sub activities layout and inflate the drawer? – Maxrunner Sep 10 '13 at 10:18
  • Would this be the right way to do this? http://stackoverflow.com/a/4922740/382115 – Maxrunner Oct 19 '13 at 15:31