Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Universal (tablet & phone) app - how best to structure - multiple layout xml or show/hide widgets?

I'm planning my first real android app and I want it to be a universal app (tablet and phone). The layout will be three list views that are populated by the previous list view (list one always has same list of items, list two will be populated based on the list one selection, list three will be populated based on list one & two selections). Once an item in list three is selected, the details will show about the item. FYI, the data is in an XML file (containment hierarchy) and the details are the leaf nodes.

I plan to have two layouts. For the tablet, I'm going to have all three list view and the details on the same screen. For the phone, I'm going to have each list occupy the entire screen and when an item in selected, slide transition to the next list view (with nav at the top for going to the previous list as well as info on what the selection(s) were from the previous lists). When an item in the third list is selected, show the details page which will also have a button to start over (i.e. go back to the first list view).

I've got the tablet view working pretty well since that's the simplest (just one screen, no transitions) - all in layout/main.xml. I've also got different layouts for different size screens (layout, layout-large, layout-small, layout-xlarge) all of which have the exact same main.xml at the moment.

So, finally to my question... How do I use the same code to populate the lists while having different user experience? I can see two options (please add more/better options)

  1. For the phone, should I continue to have one layout file (main.xml) and just have all three lists and the details on top of each other and via the slide transition, show/hide the widgets? (i.e. at first only the first list view is visible, the second list view is hidden, the third list view is hidden, the details are hidden)

  2. Should I have one layout xml for each of the screens on the phone (main.xml - initial list view, list2.xml, list3.xml, and details.xml)?

To determine if it's a tablet or not, I plan to use the code from the Google I/O app
Developing an universal android application (phone and tablet)

EDIT (2011/11/29)
Found some good online resources regarding Fragments:
http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html
http://portabledroid.wordpress.com/2011/06/22/25/
http://portabledroid.wordpress.com/2011/06/23/multi-platform-fragments-part-ii/
and the accompanying video:
http://www.youtube.com/watch?v=4BKlST82Dtg

like image 759
Ed Sinek Avatar asked Nov 23 '11 20:11

Ed Sinek


1 Answers

You want to read this document on supporting tablets and handsets, but the key to solving your problem is to use fragments.

like image 52
kabuko Avatar answered Oct 19 '22 18:10

kabuko