Android Swipe View with Tabs Without Using the V4 support library
Asked Answered
O

6

24

I've created a swipe view with tabs as described in the android documentation several times before. In fact, stepping through the Eclipse project wizard pretty much sets you up with the basic ui using a ViewPager.

My question is this:

The application I'm building will only be supporting as far back as Android 4.0 (API level 14). So, I was considering ditching the support package altogether. However, I couldn't seem to find an example of a Swipe View with Tabs not using the ViewPager (which is only available in the support package).

Is there an api level 14&> equivalent to the ViewPager and could someone give me a working example of how to implement a Swipe View with Tabs interface without using the support library.

Otherwise, could someone give a good argument as to why I shouldn't even bother, use the support package and just be happy.

Edit: What I'm looking for is an authoritative answer regarding support library specific functionality such as the ViewPager. Are these features going to eventually be merged into the core API? Or will we continue to have to include the support package for these types of functionality? Please be specific with API versions and timelines.

Edit-1/15: I'm updating this question to stop the 'Me Too' answers I'm getting. At the time of the original posting of this question, the Android Developer documentation was much more vague on the purpose of the support libraries as they relate to functionality not included in the core SDK. They have since updated their docs to clarify things:

The Android Support Library package is a set of code libraries that provide backward-compatible versions of Android framework APIs as well as features that are only available through the library APIs.

This certainly clears things up a bit and notifies developers to not expect things like the ViewPager to ever be rolled into the core SDK functionality. I've accepted the answer which was the most relevant to the issue I was having. That is how to add support package functionality to an existing project w/o having to significantly change the codebase.

Offence answered 22/10, 2013 at 16:54 Comment(4)
I think if you want to support the lower api as well, you should use Actionbarsherlock. It works smoothly as ViewPager. If you like to see, I will post the code.Matrass
@YeLinAung - I think you misread my question. I'm actually not looking to support the lower APIs. Only 14 and up. I will, however, check out ActionBarSherlock (something i've been meaning to do anyway). Thank you. :-)Offence
Your question can't really be answered by anyone but one of the Android SDK engineers. Judging by the way the compatibility package has evolved over time(and it's current state) you're stuck with it if you want the ViewPager functionality. However, you can copy its code(and modify it to use the current classes) to make your own up to date ViewPager(and ditch the support library). This of course will mean that you'll need to maintain the class yourself(basically watching if any new version of the compatibility package changes the ViewPager code).Upcoming
@Luksprog - There are or at least used to be some Android SDK engineers floating around here on S.O. So, that is exactly what I was looking for and why I opened the bounty. More out of curiosity than anything else, since the app that was being developed has already been released (w/ support package and all). Thanks for the input thought.Offence
V
12

I know this is a very old question but I think it's still relevant. I was searching for a workaround: using viewpager without having to convert all my entire projects to the v4 support library.

The answer is the v13 support library!. In this way you can have a viewpager on the activity but then use android.support.v13.app.FragmentStatePagerAdapter to maintain compability with fragments and other useful stuff.

Hope it helps some google-addicted-searcher.

Vivienne answered 14/11, 2014 at 22:49 Comment(0)
E
1

As mentioned by @Luksprog you can copy ViewPager code in your own project and replace support library references by native one. Most likely you will need to do the same with FragmentPagerAdapter, FragmentStatePagerAdapter and PagerAdapter. I grab the code from grepcode.com.

It took me 2 hours to do the trick, even though I was a beginner with android. But it mean more line of code to maintain and in the end I switched back to support library.

Earvin answered 28/8, 2014 at 21:32 Comment(0)
F
0

Now I'm no Android SDK guru, but I would just use the Support Library. Here's an excerpt from the RenderScript documentation,

"We strongly recommend using the Support Library APIs for accessing RenderScript because they include the latest improvements to the RenderScript compute framework and provide a wider range of device compatibility."

Now this is for the v8 Support Library, but I'm guessing that this recommendation can be extrapolated. It makes sense that the latest improvements will be in Android's support libraries because they can be updated independently from platform updates.

Just be sure to enable ProGuard before releasing so you can trim the excess fat of the unused parts of the API.

Frasier answered 21/1, 2014 at 6:8 Comment(0)
S
0

Also you can use the ViewFLipper class but you have to manual implement the Animations and the GestureDetector, you can find some code here

Stubblefield answered 8/1, 2015 at 8:55 Comment(0)
C
-1

You should use support library package because it provide backward-compatible versions of Android Framework APIs. Use what they recommended is the best way to deal with android from my experience.

or read this

http://www.velir.com/blog/index.php/2010/11/17/android-snapping-horizontal-scroll/

Counterinsurgency answered 10/1, 2015 at 2:26 Comment(0)
D
-1

Using the support library is encouraged in general since it contains the latest piece of code of every API. What B.Young is pointing on RenderScript applies to all the other APIs.

-------- No need to keep reading.

Let's put an example. Let say that when Android 8 is released they introduce a new class to hold values referenced to keys called FastMap. To add support for older versions, Google releases a support library with this new class, and two months later during performance tests they find a way to make it more efficient, so they release an update of that support library with the optimized version of FastMap (since Android OS is frozen into the phone).

Additionally, and since big number releases are always a bit rushed, Google realizes that they introduced a very specific bug (yehh, it happens), which gets fixed on a newer update.

So if were to build an Android app for Android 8 and above and used the built-in APIs, you'd be missing all these improvements coming in the support code.

Devon answered 12/1, 2015 at 14:4 Comment(4)
This hypothetical example is inaccurate. Functionality such as the ViewPager, which i specifically target in my question, is completely contained within the Support Library releases. You seem to insinuate that Support Library releases address bugs within the core SDK. They do not. Also, I specifically mention a scenario where the application is not supporting legacy OS versions.Offence
Apologies if the response was unclear to you. I understood you are not supporting legacy OS versions. Even in that case it is a better idea to use support libraries. Google devs are thankfully or not still human with deadlines and schedules, thus bugs, unclear and not performant code may make it into the SDK releases and docs. Most of them get fixed or improved on further release, yet support libs are also an important part of that optimization, note that support lib code will normally be the most up to date implementation.Devon
Again you are insinuating that the support library releases address bug fixes for issues in the core SDK releases. This is just not the case. Features such as the ViewPager are completely contained within the support package releases. So, if you are not supporting older OS versions and you have no plans to use these additional features, there is just no reason to use the support libraries.Offence
Not saying that support package is meant for that obviously, but that you can find improvements of the like there. You are being pretty definitive on your responses. Probably you are not looking for an answer or opinion, but that's what StackOverflow is for.Devon

© 2022 - 2024 — McMap. All rights reserved.