0

我有 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;
}
4

1 回答 1

0

我建议为此查看 ViewPager 类。它在片段之间切换。

于 2013-01-30T15:48:00.603 回答