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

Lint found fatal errors while assembling a release target.

Windows 7 all Version 64-Bit iso file Download with crack activation. (Google Drive Link)

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