Louis Tsai
1 min readJan 29, 2019

--

In the article, I mentioned that it can get a bit problematic if you want to use it with ViewPager, and I hope that’s not what you are trying to do.

But if all you want to do is use TabLayout without ViewPager, I would image what you need to do should be adding a OnTabSelectedListener to the TabLayout, and then you can use the tag in the TabLayout.Tab to figure out the destination, and then you should store that as the origin of the next click event. Once you have both origin and destination, wrap that in a convoluted switch(Java)/when(Kotlin) to map it to the correct navigation action id.

As you can see, it is not the easiest thing to deal with, and I think that’s mostly because it’s not what TabLayout is build to do: it has a lot of API and code that makes it work very well with ViewPager and Toolbar, but by itself, it’s just a glorify FrameLayout. I don’t know enough about what you want to do, but I highly suggest you to think about that part again, and see if TabLayout + Navigation Component is what you are looking for.

--

--

Louis Tsai
Louis Tsai

Written by Louis Tsai

if someone can give me a lesson of how to adult that’d be great thank you

Responses (1)