Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am developing app with android:minSdkVersion="11". From what I know, ViewPager is implemented within Compatibility Library. I have succeed to make it work in my application by adding android-support-v4.jar library, but now I am obliged to use

android.support.v4.app.FragmentActivity

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

Also I need to use

android.support.v4.app.Fragment

instead of

android.app.Fragment

It works though, I definitely don't like this approach. It destroys design of app, and I don't want to have Compatibility Library in my API Level 11 project at all.

Are there other more native ways to use ViewPager in Honeycomb+ apps?

like image 533
morphium Avatar asked Nov 08 '11 02:11

morphium


Video Answer


1 Answers

It may not have been the case at the time the accepted answer was stated, but there's import android.support.v13.app.FragmentStatePagerAdapter; in the sample code. If you use support-v13 library the constructor takes a non-support version of the FragmentManager. Note that the ViewPager must still come from v4.

I'll also add that v4 means support library for Android version 4+ (Donut 1.6), and v13 means support library for Android version 13+ (Honeycomb 3.2). Just a fact that wasn't immediately obvious to me at least. Meaning the APIs used in v4/v13 are compatible with and versions back to that point.

like image 172
Dandre Allison Avatar answered Dec 12 '22 19:12

Dandre Allison