addOnPageChangeListener is deprecated or addOnPageChangeListener not working or how to use addOnPageChangeListener in viewpager 2 in android.

The problem describe below:- 

viewpager setonpagechangelistener deprecated or viewPager.setOnPageChangeListener not working [duplicate] or setOnPageChangeListener is deprecated now or How to useaddOnPageChangeListenermethodinandroidx.viewpager.widget.ViewPager Aandroid - viewpager setonpagechangelistener deprecated.


This is deprecated.

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

@Override
public void onPageSelected(int position) {
invalidateFragmentMenus(position);
}

@Override
public void onPageScrollStateChanged(int state) {
}
});
invalidateFragmentMenus(viewPager.getCurrentItem());
}


This is new which you will have to use in viewPager 2.

 viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
    @Override
    public void onPageSelected(int position) {
        super.onPageSelected(position);
    }
});


Comments

Popular posts from this blog

Android Studio 3.5 or above usb device not detected in Android Studio or Unable to detect adb version, exit value: 0xc0000135. ADB depends on the Windows Universal C Runtime, which is usually installed by default via Windows Update. You may need to manually fetch and install the runtime package here: https://support.microsoft.com/en-ca/help/2999226/update-for-universal-c-runtime-in-windows

Lint found fatal errors while assembling a release target.

ViewModelProviders.of(this) is deprecated what to use instead ViewModelProviders.of(this) OR if you don't want to use ViewmodelFactory OR ViewModelProviders error.