Android ViewPager's onPageScrollStateChanged never gets called

后端 未结 2 1400
無奈伤痛
無奈伤痛 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.

提交回复
热议问题