Reputation: 181
I use View Pager 2 with TabLayout. I have many tabs. And I want to select a tab already created and selected.
Here when creating I am using setCurrentItem()
view_pager.setCurrentItem(mMonthsAdapter.itemCount - 1, false)
After that I have one action and then I also use setCurrentItem(). But it doesn't work this time. selects the last item and displays the first item. That is, the view pager does not work when I want to show the selected item.
Upvotes: 0
Views: 694
Reputation: 2169
Initially i was skeptic too, but it seems giving a delay is making it work
viewPager.postDelayed({ viewPager.currentItem = mMonthsAdapter.itemCount - 1 }, 100)
Try this out
Upvotes: 1