本文介绍了ViewPager - lastItem? Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序20的图像。我利用ViewPager,以显示previous /下一张图片,当用户直接在应用程式刷卡左/?我想,当用户扫描到最后的图像在右侧显示重复屏幕..

I've twenty images in my app.. I make use of ViewPager to show the previous/next images when the user swipes left/right in the app?? I would like to show "Repeat" screen when the user swipes to the right in the last image..

下面是我的code,

viewPager = (ViewPager) findViewById(R.id.main_viewpager);

ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);

PageListener pageListener = new PageListener();
viewPager.setOnPageChangeListener((OnPageChangeListener) pageListener);

int currentPage;
private class PageListener extends SimpleOnPageChangeListener{

        public void onPageSelected(int position) {
                --- some code -----
                currentPage = position;
        }
}

private class ImagePagerAdapter extends PagerAdapter {

     @Override
     public int getCount() {
          return mImages.size();
     }

     -- other implemented methods ---
}

是否有可能当用户刷到最后一个元素中的viewpager ??

Is it possible to capture the event when the user swipes to the right of the last element in the viewpager??

推荐答案

您可以通过像您开始设置自定义onChangePageListener您ViewPager实现这一目标。我不喜欢它:

You can achieve this by setting a custom onChangePageListener on your ViewPager like you started. I'd do it like:

viewPager.setOnPageChangeListener(new OnPageChangeListener() {
 //...
 @Override
public void onPageSelected(int arg0) {
  onPageChanged(arg0);
}
 //...
});

然后在你的活动

public void onPageChanged(int position) {
 if(position == SOMETHING) //do something
}

希望这有助于

这篇关于ViewPager - lastItem? Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:07