Search code examples
androidandroid-viewpager

Android ViewPager when swiping on last screen


Im having trouble figuring out how to capture a swipe event on the last page of a view pager.

Basically the requirement is that when the user is on the last page, and they try to swipe to get to the next page, the activity should close.

I've tried doing this onPageScrolled but I cant seem to differentiate a left or right swipe when in there. When on the last page, the user should still maintain the functionality to move to the previous page.

So basically the case is

When on last page
    if swipe prev (do normal behaviour)
    if swipe next (finish activity)

Can anyone provide any suggestions? Thanks


Solution

  • You should include an fake blank page to your ViewPager, when user swipes your actual last page, it comes to this fake one. When this fake one is visible finish the Activity.

    You should try this way, if it does not work, I can give you an example code.