pRaNaY pRaNaY - 1 year ago 101
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

in below code, it gives

setOnPageChangeListener is deprecated.

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

What I want to do with
is this:

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


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 + "");

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