Fragments in Android 2.2.1, 2.3, 2.0. Is this possible?

You have to use the compatibility libraries provided by Google. Here’s how you use Fragments on devices < 3.0

  • Open Eclipse
  • Window->Android SDK and AVD
  • Available Packages->Android Support package (install this)

Once installed, right click the Android project you want to add Fragment support for.

  • Build Path->Configure Build Path
  • Libraries tab
  • Add External JARs
  • Add the android-support-v4.jar (should be in the android downloads folder under extras/android/support/v4

Now you application supports Fragments. There are some key differences to using the compatibility package over using SDK 3.0+. For instance

  1. The activity classes that use fragments must extend FragmentActivity NOT Activity.
  2. instead of getFragmentManager() you have to use getSupportFragmentManager

Enjoy!!!

Leave a Comment