Yoda Yoda - 1 year ago 544
Android Question

Android ViewPager Prev/Next Button

Okay, so I'm developing an Android app that utilises a ViewPager to display pages.

Within each page, I have a set of buttons to use for navigating between pages (in addition to the swiping between pages). These buttons are for "first page", "previous page", "next page" and "last page".

What I can't figure out how to do is engineer a mechanism to enable a page change on a button click.

Anyone have any ideas?

ETA: To better explain the setup, the buttons are declared within each page's layout, and are inflated with the rest of the layout within the PagerAdapter. My problem is that I can't reference the ViewPager from within the PagerAdapter. Or at least, I can't think of a way to do it.

Answer Source
yourButton.setOnClickListener(new OnClickListener() {
   public void onClick(View view) {
      yourViewPager.setCurrentItem(page, smoothScroll);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download