Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Basically I would like to know if we can have fragment layouts in devices with Android OS < 3.0.

My app had a header on top with 5 different buttons and on start always the first button is clicked by default so the view below these buttons is for the first view. Now when you click on the second button beside it, I don't want the header images to be refreshed but the view just below it needs to be refreshed. So its like updating the fragments below the header image buttons.

So can we have fragments in Android in devices with OS < 3.0.

Sana.

like image 346
Sana Avatar asked Jun 30 '11 00:06

Sana


People also ask

In which Android version does fragments are introduced?

A fragment can implement a behaviour that has no user interface component. Fragments were added to the Android API in Honeycomb version of Android which API version 11.

Are fragments still used in Android?

Using the support library, fragments are supported back to all relevant Android versions. Fragments encapsulate views and logic so that it is easier to reuse within activities.

How many types of fragments are there in Android?

In Activity 1, there are two fragments, Fragment A and Fragment B. When we select an item from Fragment A, it gets open in Fragment B of the same activity. In the case of mobiles, there are two activities that are: Activity 1 with Fragment A and Activity 2 with Fragment B.


1 Answers

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!!!

like image 121
Spidy Avatar answered Sep 21 '22 12:09

Spidy