Skip to content Skip to sidebar Skip to footer

Switch From Dual Pane To Single Pane On Orientation Change Maintaining Fragment Stack

Currently I have a dual pane layout for both landscape and portrait on a tablet. Similar to say settings I have a single activity which loads a fragment into the left selection pa

Solution 1:

PJL, so you are on the right track here, either you can check your orientation and then show or hide specific fragments or you can have two different layouts one for Portrait and one for Landscape, in your onCreate function of your Activity you can then check if the second Fragment is available via findViewById and then instantiate it or not. The View you are looking for would just have a FrameLayout with a known Id. So make sure you understand what happens during an orientation change enter link description here A really good Fragments Example is part of the Samples of the Book The Busy Coder's Guide To Advanced Android Development the book is part of a 40$ / year description. The Sample code is free though. Check out the Fragments Example it might help with your problems. Also of course you can have a look at the example FragmentLayoutSupport.java on developer.android.com

Solution 2:

If you are using the list with action intents and uri's you can reorder the frags depending on orientation, action and uri in onCreate.

If not I guess you can keep a selectedId value in preferences and use it to keep track of your detail-view.

You will have to keep this value up to date by saving it to preferences in onclick and make sure it is updated to -1 (or suitable) on things like back (if back closes this fragment).

Post a Comment for "Switch From Dual Pane To Single Pane On Orientation Change Maintaining Fragment Stack"