Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Fragment API for API level < 11

I have came across a problem for dynamic forms in my app, which is suited for Android 2.1 and above. I know there is new Fragment API since API level 11 (Android 3.0 Honeycomb), but also I have read an article - http://android-developers.blogspot.com/2011/03/fragments-for-all.html stating Fragment Api is available also for API level lower then 11 in, so called, Compatiblity package. I have installed it via SDK, but I am not able to use is in my App, e.g. I cannot import android.app.FragmentManager, application doesn't know it.

Do you know, how to solve it? Is Fragment API truely available for older API levels? If so, how to make them going? Or is there any other solution like Fragments API? I will need for dynamic generated forms if possible

Thanks

Hmyzak

like image 750
Waypoint Avatar asked Aug 24 '11 14:08

Waypoint


People also ask

Is Android fragment deprecated?

This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle. This class was deprecated in API level 28.

What is onViewCreated in fragment?

onCreate() is called to do initial creation of the fragment. onCreateView() is called by Android once the Fragment should inflate a view. onViewCreated() is called after onCreateView() and ensures that the fragment's root view is non-null .

What is the difference between onCreate () and onCreateView () lifecycle methods in fragment?

onCreate is called on initial creation of the fragment. You do your non graphical initializations here. It finishes even before the layout is inflated and the fragment is visible. onCreateView is called to inflate the layout of the fragment i.e graphical initialization usually takes place here.

Is onActivityCreated deprecated?

Need for onActivityCreated() deprecation In such similar fashion android developers saw the tight coupling of code dependent to the Activity's life cycle. And they decided that it is not a good practice anymore to be dependent on the activity attach to do certain things inside the fragment.


2 Answers

Here's a nice tutorial on how to implement Fragments on older Android versions, hope this will help you.

like image 126
Egor Avatar answered Sep 27 '22 17:09

Egor


Android Studio:

Add a dependency for support compatibility package v4:

dependencies {
    ...
    compile 'com.android.support:support-v4:21.0.+'
    ...
}

and then use import android.support.v4.app.Fragment; instead of import android.app.Fragment; in imports.

like image 25
Jakub Turcovsky Avatar answered Sep 27 '22 19:09

Jakub Turcovsky