Reputation: 2645
I have a TabLayout connected to a ViewPager. Almost everything works correctly: I can see the tabs, I can swipe through the pages in the ViewPager and the tabs update.
However, I cannot find how to allow the user to click on a tab to select instead of swiping...
Does anyone have any idea how to do this?
Upvotes: 2
Views: 1709
Reputation: 2645
The issue was caused by using a FrameLayout with two children when the FrameLayout is supposed to have only one child. This link described the issue: Not possible to click a Button
I had:
<FrameLayout>
<TabLayout>
<ViewPager>
</FrameLayout>
The FrameLayout only passes events to the last direct child, so the ViewPager was getting all the events. That is why it still allowed me to swipe the view correctly.
The solution is to use:
<FrameLayout>
<LinearLayout>
<TabLayout>
<ViewPager>
</LinearLayout>
</FrameLayout>
That way both the TabLayout and the ViewPager get events.
Upvotes: 6