pRaNaY pRaNaY - 1 year ago 115
Android Question

viewPager.setOnPageChangeListener not working

I am using Android Studio to develop an app targeting API level 22 and using compileSdkVersion level is 23.
When I am trying to implement

ViewPager.OnPageChangeListener()
in below code, it gives


setOnPageChangeListener is deprecated.


viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {}


What I want to do with
viewPager.setOnPageChangeListener()
is this:

viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
txtPropertyOverviewImageCount.setText(position + "/" + GalleryImages.length);
//GalleryImage have no of item is same size of viewpager
//i want O/P like this
// 1/8
// 2/8
// 3/8
LogUtils.Log_e("CurrentPage", position + "");
}

@Override
public void onPageScrollStateChanged(int state) {

}
});

Answer Source

yes setOnPageChangeListener is deprecated in favour of addOnPageChangeListener which allows you to register more than one listener, in case you need it. You can find the documentation here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download