我有3个片段,我想把它显示为一本书。用户将从列表视图中选择一个章节,因此,新活动将启动当前片段,上一个和下一个。这段代码将创建三个片段。 现在,问题是当前片段是第一个,我想把它放在next和previous之间,并在活动开始时将它放在前面。
@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;
}
答案 0 :(得分:0)
我建议查看ViewPager类。它在片段之间切换。