0

I'm building a basic app for Android (and am new to anything but iOS), and I'm only targeting APIs 15-22, so I've been using the main library in comparison to the support library for things like fragments (that is, importing android.app.Fragment as opposed to android.support.v4.app.Fragment). However, it seems ViewPager requires the fragments to be from the support library, so either I need to edit all my code to use the support library or I can't use ViewPager. I can't help but feel that think this reflects really poorly on Android as an OS. Is there any way around this? Is there any harm in using the support library for newer APIs (15-22)?

Thank you.

Jameson
  • 4,198
  • 4
  • 17
  • 31
  • How are you importing ViewPager? – xyz Jul 14 '15 at 14:37
  • 1
    Look at [this question](http://stackoverflow.com/questions/17295497/fragment-or-support-fragment) for some reasons why you should switch to just using `android.support.v4.app.Fragment` and if you decide to stick with `android.app.Fragment`, look at [this answer](http://stackoverflow.com/a/17556988/4896787) for how to use them with `ViewPager` – Joseph Roque Jul 14 '15 at 14:42
  • 2
    generally speaking, using the support library not only helps you with lower API levels, but also helps with getting a consistent experience across those. (bottom line: use the support library. I don't really understand myself why there is a implementation of fragments in the base android SDK) – njzk2 Jul 14 '15 at 14:44
  • Should I be using v4 or another version when I use the support library? What exactly is the difference? – Jameson Jul 14 '15 at 15:59

1 Answers1

2

However, it seems ViewPager requires the fragments to be from the support library, so either I need to edit all my code to use the support library or I can't use ViewPager

this is correct, viewpager is made to be used with the support library fragment class and not android.app.Fragment.

There is no harm in using the support library, in fact its recommended you use the support library stuff as it is updated more often and provides a more consistent experience with older devices

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • Why isn't there just one standard library? It seems so unnecessarily complicated. – Jameson Jul 14 '15 at 15:47
  • And moreover, there are multiple versions of the support library? Should I be using v4 or another version? – Jameson Jul 14 '15 at 15:59
  • 1
    What do you mean one standard library? The multiple versions of the library ie. v4, v7 indicate what version of Android you can start using the library on. v4 means any api from api 4 and up – tyczj Jul 14 '15 at 16:08
  • So is there much of a difference, if any, if I'm only programming for APIs 15 and up? – Jameson Jul 14 '15 at 16:15
  • 2
    @Jameson well different support library version (v4,v7) had different api's however v7 includes the v4 library so in most cases you can just use the v7 library – tyczj Jul 14 '15 at 16:18