1

I'm using a FragmentTransaction to replace a fragment in a container like this:

activity.getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.abc_fade_in, R.anim.abc_fade_out).replace(R.id.container, fragmentToShow).addToBackStack(null).commit();

The problem is that a PreferenceFragment can not be converted to support v4 fragment. How can I use a PreferenceFragment like that?

JJ Ab
  • 492
  • 4
  • 15
  • This link might help you. http://stackoverflow.com/questions/9783368/alternatives-to-preferencefragment-with-android-support-v4 – Pravin Divraniya Mar 15 '16 at 14:30
  • I saw that but I can't add the PreferenceFragmentCompat.. it says "The import android.support.v7.preference cannot be resolved" even though the support appcompat is being used by me – JJ Ab Mar 15 '16 at 14:33
  • Add appcompact v7. dependencies { compile "com.android.support:appcompat-v7:18.0.+" } – Pravin Divraniya Mar 15 '16 at 16:35
  • where do I do that? I don't use gradle. working with eclipse – JJ Ab Mar 16 '16 at 07:07
  • This link help you how to add it in eclipse. http://stackoverflow.com/questions/24998368/the-import-android-support-v7-cannot-be-resolved – Pravin Divraniya Mar 16 '16 at 09:46

1 Answers1

8

I did the same problem and I solved in those steps:

  1. Add to gradle file dependencies this line
    compile 'com.android.support:preference-v7:23.3.0'
  2. Extends your SettingFragment with
    'PreferenceFragmentCompat'
  3. Import in your class
    import android.support.v7.preference.PreferenceFragmentCompat;