Reputation: 59
Regarding TabLayout, when I swipe left or right, the next tab is inflated - fragment is shown properly - however, when I click the tab title, it doesn't not automatically change to the proper fragment. Does this have to be implemented manually? Seems a bit weird as swiping works by default, so clicking should as well.
Upvotes: 3
Views: 1428
Reputation: 3933
You could implement a onTabSelectedListener
and use your viewPager
to change the fragment
.
Example:
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener()
{
@Override
public void onTabSelected(TabLayout.Tab tabSelected)
{
viewPager.setCurrentItem(tabSelected.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tabSelected){}
@Override
public void onTabReselected(TabLayout.Tab tabSelected){
}
});
Upvotes: 4