Fragments in Android 2.2.1, 2.3, 2.0. Is this possible?
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
- The activity classes that use fragments must extend
- instead of
getFragmentManager()you have to use
android fragments make it work on android 2.2
MainActivity.java to extend
FragmentActivity instead of just
Using the v4 Library APIs
How to provide support for Fragments and ActionBar for App which supports Android 2.2+ devices?
All your code is look good , just keep in mind that you have two xml file activity_main.xml one will be in layout folder and second will be in layout-port folder.
For complete working demo of Vogella check out this link project.
Error inflating class android 2.2 with drawer navigation
In case anybody has the same problem the issue was the
crushed the whole app. So I removed it in the pre-Honeycomb versions
Choice of design between using Inheritance or Fragments
That depends on your situation. Lets say you have an Activity A that does some stuff and an Activity B that does exactly the same stuff like A but a little bit more (like adding a few buttons).
In that case you can let Activity B extend your Activity A.
B just adds what's missing.
If Activity A and B have a lot in common, but if there are also slight differences, to be precise: if Activity A contains code that is not needed by B you should create one abstract base class C for both activities A and B which contains only the common sub-set of code. Let A and B extend C and add to A and B their individual extra-code.
As for using Fragments or not: I'd go for it. In the long run you'll have less troubles with supporting tablets / multiple screen sizes and you can easily re-use them in different contexts.
Let's assume your boss / client suddenly wants that fancy ViewPager feature we know from Google Play (swiping screens left and right for switching categories). If you were using Fragments in the first place, this change can be done very easily and quickly.
If you were using Activities instead, you need to re-arrange a great deal of code.
How to Use an Arrayadapter in Android of Custom Objects
Android Sdk 22 - Searchview Rendering Problems
Adding Opencv to Native C Code Through Cmake on Android Studio
How to Implement Drag and Drop in Android 2.2
Refresh Fragment UI from Fragmentactivity
Quaternion Rotation Does Not Work as Excepted
Where Did the "Createfromresourceid()" Go
Validate Username and Email Crashed and Cannot Insert to Firebase Database
How to Determine Which Dependency Causes Google Play Openssl Warning
How to Keep the Spaces at the End And/Or at the Beginning of a String
How to Get Color-Int from Color Resource
Standard Android Menu Icons, for Example Refresh
Difference Between Surfaceview and View
Error: No Toolchains Found in the Ndk Toolchains Folder for Abi with Prefix: Llvm
Swipe to Dismiss for Recyclerview
Versioncode VS Versionname in Android Manifest
Java.Lang.Noclassdeffounderror:Failed Resolution of :Lorg/Apache/Http/Protocolversion