I have an application which support android 2.2 library.In this app I want to use fragment someone suggest me ,if possible how to do it.
Thanks
A fragment has its own layout and its own behaviour with its own life cycle callbacks. You can add or remove fragments in an activity while the activity is running. You can combine multiple fragments in a single activity to build a multi-pane UI. A fragment can be used in multiple activities.
According to the Android documentation, a fragment is a part of applications user interface that is bound to an activity. Fragments have their lifecycle and layouts or UI components. Fragments help enrich your UI design, pass data between different screens, and adapt to different device configurations.
Add a fragment to an activity You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your activity.
Yes you need to use the support library. What is important to know is that you can use the support library on honeycomb and icecream sandwich as well. In that way you can use the same build on all the platforms. You need to use the SDK 4.0 as target with minsdk 2.2. A different problem are the settings activities. For Honeycomb+ you can use the PreferenceFragment that are not supported by the support library yet. If you use the new onBuildHeaders method of PreferenceActivity and the "header" tag in the settings.xml you need to put that xml in a separated folder like for example xml-v12 to specify that it is used only with API-12+.
For the settings have a look to: http://developer.android.com/reference/android/preference/PreferenceActivity.html there is a good example of the onBuildHeaders
For the support library: http://developer.android.com/sdk/compatibility-library.html
I think that, in order to include fragment in Android 2.2, you need to add android-support-v4.jar
to your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With