Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to catch changing of View Pager slides

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 296
    Comment on it

    After creating a ViewPager (as I also described here ViewPager) we need to catch the changing of slides event.

    To do this we have a listener OnPageChangeListener i.e, ViewPager.OnPageChangeListener that invokes whenever we chance the page or increment the page.


    We simply use it through addOnPageChangeListener(OnPageChangeListener) this method.Below is the code

     mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    
                }
    
                @Override
                public void onPageSelected(int position) {
                    if (position == 0) {
                       
                    } else if (position == 1) {
                       
    Toast.makeText(getActivity(),"Page : "+position,Toast.LENGTH_SHORT).show();
    
                    } else if (position == 2) {
                     
    Toast.makeText(getActivity(),"Page : "+position,Toast.LENGTH_SHORT).show();
    
                    }
                    else if (position == 3) {
    
                     Toast.makeText(getActivity(),"Page : "+position,Toast.LENGTH_SHORT).show();
    
                    }   else if (position == 4) {
    
                        Toast.makeText(getActivity(),"Page : "+position,Toast.LENGTH_SHORT).show();
                    }
                }
    
                @Override
                public void onPageScrollStateChanged(int state) {
    
                }
            });

    Hope it will help you.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: