MainActivity
private void setupTabHost() {
for(int i=0; i<tabs.length; i++) {
tabHost.addTab(tabHost.newTabSpec(tabs[i].getLabel()).setIndicator(tabs[i].getLabel()), MyFragment.class, null);
}
}
ViewPager
List<Fragment> fragmentList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager fm, MainActivity.TabData[] tabs) {
super(fm);
this.tabs = tabs;
for(MainActivity.TabData tab : tabs){
Bundle bundle = new Bundle();
bundle.putSerializable("URL", tab.getUrl());
MyFragment fragment = new MyFragment();
fragment.setArguments(bundle);
fragmentList.add(fragment);
}
}
@Override
public Fragment getItem (int i) {
return fragmentList.get(i);
}
这个ViewPager
可以调用tabhost
创建的原始片段吗?
这段代码似乎是,它会从fragment
创建一个新的list<Fragment>
?