Using android.app.Fragment with ViewPager in Android 3.0+

I am developing an application with Android: minSdkVersion = "11". From what I know, ViewPager is implemented in the compatibility library. I managed to get it to work in my application by adding the android-support-v4.jar library, but now I have to use

android.support.v4.app.FragmentActivity

because I need getSupportFragmentManager () for FragmentPagerAdapter instead of the new android.app.Activity getFragmentManager ().

I also need to use

android.support.v4.app.Fragment

instead

android.app.Fragment

It works, although I definitely don't like this approach. It destroys the design of the application, and I do not want to have a compatibility library in my level 11 API project at all.

Are there other more familiar ways to use ViewPager in Honeycomb + applications?

+7
source share
2 answers

Perhaps this is not the case when the accepted answer was accepted, but there import android.support.v13.app.FragmentStatePagerAdapter; in the sample code . If you use the support library-v13, the constructor takes a non-supporting version of FragmentManager . Note that the ViewPager must still come from v4.

I will also add that v4 means the support library for Android version 4+ (Donut 1.6), and v13 means the support library for Android version 13+ (Honeycomb 3.2). Just a fact that was not immediately clear to me, at least. The API value used in v4 / v13 is compatible with versions and versions back to this point.

+13
source

Copy the FragmentPagerAdapter into your code and modify it to use android.app.Fragment etc. Or implement your own PagerAdapter yourself, it does not depend on fragments at all.

+7
source

All Articles