viewpager setonpagechangelistener deprecated
Today I'm trying to set ViewPager.setOnPageChangeListener
and I've found out that it's deprecated.
Solution 1:
ViewPager.setOnPageChangeListener
is deprecated now. Need to use ViewPager.addOnPageChangeListener
instead.
for example,
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) {
}
});
You can find this Here.
Solution 2:
this worked for me:
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener(){
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
conterchange.setText(""+(1+position));
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
Solution 3:
Use ViewPager.addOnPageChangeListener instead of ViewPager.setOnPageChangeListener.