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)