Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewpager scrolling finish event

Tags:

android

I have a viewpager that dislapys text views. I have header layout above it. What i want is to hide or display this header when the user click on the screen. but not when the scrolling is occur. I tried the ViewPager.onPageChangeListener. But with no success. What i need is how to know when the swapping between pages finishes. The onPageScrollStateChange didnt help i create an instance variable to hold the state and keep updating it when this method call so i can use it in my onclick listener to now if the page is scrolling or not but with no success

like image 755
user1320899 Avatar asked Apr 22 '12 00:04

user1320899


1 Answers

    mViewPager.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) {
            if(ViewPager.SCROLL_STATE_IDLE == state){
                //Scrolling finished. Do something.
            }
        }
    });
like image 150
Vladimir Petrovski Avatar answered Sep 27 '22 15:09

Vladimir Petrovski