ViewPager with PreferenceFragment

suggest change

Until recently, using would prevent the usage of a PreferenceFragment as one of the Fragments used in the FragmentPagerAdapter.

The latest versions of the support v7 library now include the PreferenceFragmentCompat class, which will work with a ViewPager and the v4 version of FragmentPagerAdapter.

Example Fragment that extends PreferenceFragmentCompat:

import android.os.Bundle; 
import android.view.View; 
public class MySettingsPrefFragment extends PreferenceFragmentCompat { 
    public MySettingsPrefFragment() { 
        // Required empty public constructor 
    public void onCreate(Bundle savedInstanceState) { 
    public void onCreatePreferences(Bundle bundle, String s) { 

You can now use this Fragment in a subclass:

private class PagerAdapterWithSettings extends FragmentPagerAdapter {

    public PagerAdapterWithSettings(FragmentManager supportFragmentManager) {

    public Fragment getItem(int position) {
        switch(position) {
            case 0:
                return new FragmentOne();

            case 1:
                return new FragmentTwo();

            case 2:
                return new MySettingsPrefFragment();

                return null;
    // .......


Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents