我有 3 个片段,我想把它作为一本书展示。用户将从列表视图中选择一个章节,一个新的活动将启动当前片段,上一个和下一个。此代码将创建三个片段。现在,问题是当前片段是第一个,我想把它放在下一个和上一个之间,并在活动开始时将它放在前面。
@Override
public Fragment getItem(int position) {
Fragment fragment = new CurrentSectionFragment();
Bundle args = new Bundle();
switch(position) {
case 0: {
fragment = new rewaya.books.gaddhayatek.fragment.PreviousSectionFragment();
args.putInt(PreviousSectionFragment.ARG_SECTION_NUMBER, position);
args.putString(PreviousSectionFragment.PreviousParagraph, PreviousParagraph);
fragment.setArguments(args);
return fragment;
}
case 1: {
fragment = new rewaya.books.gaddhayatek.fragment.CurrentSectionFragment();
args.putInt(CurrentSectionFragment.ARG_SECTION_NUMBER, position);
args.putString(CurrentSectionFragment.Paragraph, Paragraph);
fragment.setArguments(args);
return fragment;
}
case 2: {
fragment = new rewaya.books.gaddhayatek.fragment.NextSectionFragment();
args.putInt(NextSectionFragment.ARG_SECTION_NUMBER, position);
args.putString(NextSectionFragment.NextParagraph, NextParagraph);
fragment.setArguments(args);
return fragment;
}
}
return fragment;
}