Search code examples
androidandroid-fragmentsandroid-viewpagerandroid-support-libraryfragmentpageradapter

How to use a PreferenceFragment in a FragmentPagerAdapter (android.support.v4)?


In my MainActivity, I am using a android.support.v4.view.ViewPager with a android.support.v4.app.FragmentPagerAdapter. I have seen many questions like this one, except the answers say to use android.support.v13.app.FragmentPagerAdapter, which is now deprecated. What is the current, proper, up-to-date answer of how to include a android.preference.PreferenceFragment inside a android.support.v4.app.FragmentPagerAdapter?

Note: My minimum sdk version is 16. Note 2: I'd prefer to use only android/google provided libraries, if possible.

I have no idea if this is possible, but can the PreferenceFragment be shown inside an android.support.v4.app.Fragment to combat this issue?


Solution

  • You can use the android.support.v7.preference.PreferenceFragmentCompat as an alternative to PreferenceFragment that works with the android.support.v4.app.FragmentPagerAdapter as discussed in this Google+ post

    It is part of the v7 Preference Support Library.