Usually in the examples it is advised to make the settings screen like this:
Create a file pref_headers.xml of approximately the following content:
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" > <header android:fragment="ru.my.proj.MActivity$PrefFragment1" android:title="@string/pref_header_1" /> <header android:fragment="ru.my.proj.MActivity$PrefFragment2" android:title="@string/pref_header_2" /> </preference-headers>
And for each category of settings, create your own Fragment of the form:
public static class PrefFragment1 extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_1); } }
But if there are a lot of such categories, is it not better to describe one Fragment with its constructor:
public static class PrefFragment extends PreferenceFragment { private int resource; public PrefFragment(int res) { resource = res; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(resource); } }
But how now, from pref_headers.xml, call the constructor described above?