I want to use com.google.android.material.tabs.TabLayout component with Android\'s new ViewPager implementation androidx.viewpager2.widget.Vi
Initialize the TabLayoutMediator object with an object of TabLayout, ViewPager2 , autoRefresh -- boolean type, and an object of OnConfigurationChangeCallback.
TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(tabLayout, viewPager2, true, new TabLayoutMediator.OnConfigureTabCallback() {
@Override
public void onConfigureTab(TabLayout.Tab tab, int position) {
// position of the current tab and that tab
}
});
Finally just call attach() to the TabLayoutMediator object to wire up the tablayout to the viewpager :-
tabLayoutMediator.attach();
autoRefresh - key if set to true -- ( By default its set to true )
RECREATESall the tabs of thetabLayoutifnotifyDataSetChangedis called to the viewpageradapter.
Use the contents of TabLayoutMediator.java