9

If I do not need to grant support for older versions of android and can just use API 17, is there an alternative way to implement the much advertised horizontal swipe (like in gmail) and not use viewpager, fragmentsactivities (new APIs already have fragments...) etc. to get rid of the support library?

All the tutorials I've found for horizontal swipe show how to do it using the support library and FragmentActivities. Otherwise what is the advantage of the new APIs if I cannot use their native classes and methods?

Danny
  • 344
  • 1
  • 4
  • 15

2 Answers2

4

to get rid of the support library

ViewPager only exists in the Android Support Library. The Android Support Library is not just for backports.

new APIs already have fragments

ViewPager can use native API Level 11 fragments, though you may need to create your own PagerAdapter. Or, you can use ViewPager without any fragments, using just ordinary View or ViewGroup objects for the pages.

is there an alternative way to implement the much advertised horizontal swipe

You are welcome to write your own replacement for ViewPager. Most developers prefer to reuse ViewPager, for reduced development and maintenance costs.

There is also HorizontalScrollView, an open source HorizontalListView floating around, and so on.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 4
    Ok, so I guess I should just give the best answer to this and go ahead with the support library. I do not have any specific reason not to use viewpager beside the fact that i wanted to keep the app support library free. Since horizontal swipe is so recommended on the android guidelines I thought there was an alternative way embedded natively in the new APIs that I was ignoring. I thought that the approach that is usually described uses the support library since most of devs probably want to keep the app compatible with older android version that are still widely spread. – Danny Feb 16 '13 at 15:03
  • @CommonsWare I am facing an issue while using the ViewPager. Can you please look in to this... http://stackoverflow.com/questions/30303488/how-to-update-fragments-data-used-in-viewpager-view-is-not-showing-the-updated – Arun Badole May 20 '15 at 11:19
1

You can write your own FragmentPagerAdapter which works with android.app.Fragment instead of android.support.v4.app.Fragment to minimize dependency on the support library. You only need to create your own class for the adapter (based on FragmentPagerAdapter from support library which source can be found in folder <android-sdks>/extras/android/support/v4/src/java/android/support/v4/app/). Only modification is in the import section - you should reference Fragment, FragmentManager and FragmentTransaction from android.app instead of android.support.v4.app.