Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Swipe View with Tabs Without Using the V4 support library

Tags:

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.

like image 395
SBerg413 Avatar asked Oct 22 '13 16:10

SBerg413


People also ask

How to make swipe screen in Android?

You can create swipe views using AndroidX's ViewPager widget. To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .

What is ViewPager in Android?

Layout manager that allows the user to flip left and right through pages of data. You supply an implementation of a PagerAdapter to generate the pages that the view shows. ViewPager is most often used in conjunction with android. app.

How to create ViewPager in Android studio?

Android ViewPager widget is found in the support library and it allows the user to swipe left or right to see an entirely new screen. Today we're implementing a ViewPager by using Views and PagerAdapter. Though we can implement the same using Fragments too, but we'll discuss that in a later tutorial.


2 Answers

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.

like image 137
garlix Avatar answered Sep 30 '22 20:09

garlix


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.

like image 35
Geoffrey Marizy Avatar answered Sep 30 '22 20:09

Geoffrey Marizy