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
- The activity classes that use fragments must extend
FragmentActivity
NOTActivity
. - instead of
getFragmentManager()
you have to usegetSupportFragmentManager
Enjoy!!!