我正在使用FragmentPagerAdapter
包含两个片段。两个片段从扩展片段的抽象片段扩展。我无法在创建片段时获取片段的页面标题,因为标题作为参数传递给片段:
FragmentActivity 的内部类:
ArrayList<AbstractFragment> fragments = new ArrayList<AbstractFragment >();
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return fragments.get(position).getTitle();
}
}
抽象片段:
protected Bundle data;
protected String title;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
data=this.getArguments();
numberSetData=data.getParcelableArrayList(KEY_CHART_DATA);
title=data.getString(KEY_CHART_TITLE);
//Title should is determined here.
}
public abstract String getTitle();
具体片段:
@Override
public String getTitle(){
return title;
}
如果我滑动到下一个片段,问题就解决了,标题会出现,但在创建时不会出现。有什么建议吗?