setupWithViewPager

open fun setupWithViewPager(@Nullable viewPager: ViewPager)

The one-stop shop for setting up this TabLayout with a ViewPager.

This is the same as calling setupWithViewPager with auto-refresh enabled.

Parameters

viewPager

the ViewPager to link to, or null to clear any previous link


open fun setupWithViewPager(@Nullable viewPager: ViewPager, autoRefresh: Boolean)

The one-stop shop for setting up this TabLayout with a ViewPager.

This method will link the given ViewPager and this TabLayout together so that changes in one are automatically reflected in the other. This includes scroll state changes and clicks. The tabs displayed in this layout will be populated from the ViewPager adapter's page titles.

If autoRefresh is true, any changes in the PagerAdapter will trigger this layout to re-populate itself from the adapter's titles.

If the given ViewPager is non-null, it needs to already have a PagerAdapter set.

Parameters

viewPager

the ViewPager to link to, or null to clear any previous link

autoRefresh

whether this layout should refresh its contents if the given ViewPager's content changes