Android ViewPager's onPageScrollStateChanged never gets called

后端 未结 2 1371
無奈伤痛
無奈伤痛 2021-02-03 23:43

I have extended the ViewPager class and implemented onPageChangeListener. I use this ViewPager in conjunction with a CirclePageIndicator inside a SherlockFragment. The ViewPager

相关标签:
2条回答
  • 2021-02-04 00:02

    When you use PageIndicator in conjunction with the Viewpager then the onPageChangeListener of the ViewPager is not called. I don't know the reason for this but this happened when I was using both. May be cause the page indicator consumes the page change event. Instead you should set a page change listener to the PageIndicator and it will be called when the page changes. Here is how you can do this:

    indicator.setOnPageChangeListener(new OnPageChangeListener() {
    
            @Override
            public void onPageSelected (int page)
            {
                //page changed
            }
    
            @Override
            public void onPageScrolled (int arg0, float arg1, int arg2)
            {
            }
    
            @Override
            public void onPageScrollStateChanged (int arg0)
            {
            }
        });
    

    I hope this will help. Feel free to discuss.

    0 讨论(0)
  • 2021-02-04 00:18

    setOnPageChangeListener is deprecated. use addOnPageChangeListener

    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    
            }
    
            @Override
            public void onPageSelected(int position) {
    
            }
    
            @Override
            public void onPageScrollStateChanged(int state) {
    
            }
        });
    
    0 讨论(0)
提交回复
热议问题