Problem
Rotating a device from a one-pane portrait PreferenceScreen
to a two-pane landscape PreferenceScreen
, causes landscape to only show as one-pane. Does NOT occur when viewing the headers screen.
Setup
This is for ICS and up only. I have a PreferenceActivity
which loads preference-headers
. Each header links with a Fragment
, which in turn loads a PreferenceScreen
. Pretty run of the mil.
Details
Everything worked well until I noticed that Android will only auto-switch to a two-pane look for certain screens. After some research I learned from a Commonsware post that Android will only do so for sw720dp. Bit of a waste if you ask me since many devices def have plenty of room for two-panes. So I overrided the onIsMultiPane()
method to return true for w600dp and up. Worked like a charm....kinda.
Given a device which will show single-pane in portrait and dual-pane in landscape; viewing the headers in portrait and rotating to landscape, works fine. However if one selects a header and loads it's subsequent screen in portrait mode, then rotate to landscape the device will stay single-pane instead of switching back to dual-pane. If you then back navigate to the headers screen, it'll return to a dual-pane look except that it won't pre-select a header. As a result the detailed pane stays blank.
Is this intended behavior? Anyway to work around it? I tried overriding onIsHidingHeaders()
as well but that just caused everything to show a blank screen.
Code
Preference Activity:
public class SettingsActivity extends PreferenceActivity {
@Override
public void onBuildHeaders(List<Header> target) {
super.onBuildHeaders(target);
loadHeadersFromResource(R.xml.preference, target);
}
@Override
public boolean onIsMultiPane() {
return getResources().getBoolean(R.bool.pref_prefer_dual_pane);
}
}
A Preference Header Frag:
public class ExpansionsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_expansions);
}
public static ExpansionsFragment newInstance() {
ExpansionsFragment frag = new ExpansionsFragment();
return frag;
}
}