Android的ViewPager preV /下一个按钮按钮、Android、ViewPager、preV

2023-09-05 10:21:31 作者:猫忘了鱼尾纱

好了,所以我开发一个Android应用程序,它利用ViewPager显示的页面。

在每个页面上,我有一组按钮用于网页间导航(除网页之间的刷卡)。这些按钮是第一页,previous页,下一页和最后一页。

我想不出什么如何做的是设计一种机制,使一个按钮,点击页面改变。

任何人有什么想法?

ETA:为了更好地解释了设置,按钮每个页面的布局中声明,并充入的PagerAdapter内布局的其余部分。我的问题是我无法从PagerAdapter中引用的ViewPager。或者至少,我不能想办法做到这一点。

解决方案

  yourButton.setOnClickListener(新OnClickListener(){
   @覆盖
   公共无效的onClick(视图查看){
      yourViewPager.setCurrentItem(页,smoothScroll);
   }
});
 

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

android viewpager indicator

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.

解决方案

yourButton.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View view) {
      yourViewPager.setCurrentItem(page, smoothScroll);
   }
});