0

I have a ViewPager2 and a TabLayout that contains two tabs. How do I select second tab when first entering the page?

EDIT: I managed to select second tab like so: tabLayout.getTabAt(1).select() But I have another problem now, because the page under it is the page that corresponds to the first tab and viewPager.setCurrentItem(1, true) doesn't seem to fix it.

alexC
  • 133
  • 1
  • 12

1 Answers1

2

You can use,

viewPager.post {
  viewPager.setCurrentItem(1, false)
}

Pass false to directly jump to second page instead of a smooth scroll.

Arpit Shukla
  • 9,612
  • 1
  • 14
  • 40