0

I am playing around the fragments tutorial found here on section 21. It works fine when my build target is android 4.0 but when i try to change it to make it work with android 2.2, i get Error inflating class fragment on the line setContentView(R.layout.main); on MainActivity class.

I already added the support package, changed classes ListFragment and DetailFragment to extend android.support.v4.app.ListFragment and android.support.v4.app.Fragment respectively. There are no compile errors.

Did I miss something? TIA!

--EDIT--- Made it work. I changed DetailActivity.java and MainActivity.java to extend FragmentActivity instead of just Activity. Everything's okay now. But still don't know why I have to do that.

yojoannn
  • 626
  • 1
  • 9
  • 26
  • Check the steps here: http://stackoverflow.com/questions/6528691/fragments-in-android-2-2-1-2-3-2-0-is-this-possible – Calvin Mar 23 '12 at 05:40
  • Could you please post the stack trace (printed in LogCat); I'm guessing your calling a method or class that's not available in android 2.2. – junkdog Mar 24 '12 at 02:54
  • Hi, you had to do that because fragments were not an original part of Android 2.X. Fragments came around API 11, which is version 3.0 Honeycomb I believe. This being said, you need to utilize the Android Support Library, which gets included in your project to allow fragment "simulation" in older versions of Android. That's why. – AutoM8R Jan 31 '14 at 02:56

1 Answers1

0

Changed DetailActivity.java and MainActivity.java to extend FragmentActivity instead of just Activity.

Using the v4 Library APIs

yojoannn
  • 626
  • 1
  • 9
  • 26