20

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

Waypoint
  • 17,283
  • 39
  • 116
  • 170
  • You need to add the Jar. – Blundell Aug 24 '11 at 14:13
  • **Really this link will fulfill your needs.** [Here][1] [1]: http://stackoverflow.com/questions/6528691/fragments-in-android-2-2-1-2-3-2-0-is-this-possible – vinoth May 29 '13 at 10:45
  • Here's a nice [tutorial](http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/) on how to implement `Fragments` on older Android versions, hope this will help you. – Egor Aug 24 '11 at 14:12

3 Answers3

5

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.

Jakub Turcovsky
  • 2,096
  • 4
  • 30
  • 41
0

Use ActionBarSherlock. It comes with a lot of working examples.

Roger Garzon Nieto
  • 6,554
  • 2
  • 28
  • 24
0

You need to add the package to the build path.

Alex Florescu
  • 5,096
  • 1
  • 28
  • 49
  • 1
    You should add such questions as comments, not as answers – Egor Aug 24 '11 at 14:15
  • @Egor: If you prefer that I rephrase it as a statement rather than a question, I can do that, but this is what I believed the problem to be. *Comments should not be used when creating an answer to a question. In that case it is best to submit an answer, or vote up the best answer if you already see it listed.* (http://meta.stackexchange.com/questions/19756/how-do-comments-work) – Alex Florescu Aug 24 '11 at 14:29