implement with custom PageAdapter
First , create your custom PagerAdapter
extends FragmentStatePagerAdapter
and override some method.
and in MainActivity you can use with method addOnPageChangeListener()
after instance to change layout when swipe. Configure layout tab fragment in class Pager
, for override method example :
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
return new TabSatu();
case 1:
return new TabDua();
}
return null;
}
and with change title with String Array, for example method
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
TabLayout setup with ViewPager use method setupWithViewPager()
with return object ViewPager.