androidlistviewpaginationswipe

Android Vertical Listview with horizontal scrolling on top


I have an android app in which I have a multiple "Categories" each with some items associated with it. Like an online electronics shop for instance where you would have categories such as Computers, Printers, cameras etc. as categories and then each of those would have some items in them.

These categories should be displayed as "tabs" in the top of the screen where can select a tab to show which items is associated with it. This works fine as it is but what I want is to be able to change category by sliding left or right on the screen as well. Image of a single tab selected (the first)

As you can see on the image the first tab is selected. Now what I need is when the user swipes right, tab 2 will be selected instead and all the items in the listview would be changed of course to those of category 2 (tab2). All the items (independent of category) have the same design which is why I only use one listview. Some of the problems I have faced are:

Hope anyone can help.


Solution

  • You're on the right track with a ViewPager, but to get the correct functionality for the top, you should use a library by Jake Wharton.

    https://github.com/JakeWharton/ViewPagerIndicator

    You can set your top elements, and the pager will correspond with a proper fragment in the adapted callback.