0
這是活動的onCreateAndroid的 - 刪除選項卡和TabFragment
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("A"));
tabLayout.addTab(tabLayout.newTab().setText("B"));
tabLayout.addTab(tabLayout.newTab().setText("C"));
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
TabFragmentPagerAdapter adapter = new TabFragmentPagerAdapter(getSupportFragmentManager(),tabLayout.getTabCount());
viewPager.setAdapter(adapter);
適配器
public class TabFragmentPagerAdapter extends FragmentStatePagerAdapter {
private int numberOfTabs;
public TabFragmentPagerAdapter(FragmentManager fm, int numberOfTabs) {
super(fm);
this.numberOfTabs = numberOfTabs;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
FragmentA a = new FragmentA();
return a;
case 1:
FragmentB b = new FragmentB();
return b;
case 2:
FragmentA c = new FragmentC();
return c;
default:
return null;
}
}
@Override
public int getCount() {
return numberOfTabs;
}
}
我能夠使用tabLayout.removeTabAt(1)
刪除選項卡,但我如何在位置1刪除片段?
什麼是tabItems? – Coder
其你arraylist –
我沒有一個。 Arraylist的? – Coder