I need to assign a unique tab id to my tabs created using viewpager and tablayout?

后端 未结 3 1534
清酒与你
清酒与你 2021-01-11 23:59

I created an Tab based application using viewpager and Tablayout. When i click a button new tabs are created with a child fragment.

What I need is to assign differe

3条回答
  •  攒了一身酷
    2021-01-12 00:26

    You can use the setTag() method of TabLayout.Tab to use any Object you want as an identifier. You could do this in your setupTabLayout() method, where you are setting your custom view for each Tab.

    For example, to use a String:

    tabLayout.getTabAt(i).setTag("tab_" + i);

    You can then later check the tag of each tab in your parent fragment with tab.getTag();

提交回复
热议问题