简体   繁体   English

将片段带到前面

[英]Bring fragment to front

I have 3 fragment which i want to show it as a book. 我有3个片段,我想将其显示为书。 The user will select a chapter from the listview so ,a new activity will start the current fragment, previous and next. 用户将从列表视图中选择一个章节,这样,一个新的活动将开始当前片段,上一个和下一个。 This code will create three fragment. 这段代码将创建三个片段。 Now, the problem is the current fragment is the first and I want to put it between next and previous and bring it in the front when the activity starts. 现在,问题是当前片段是第一个片段,我想将其放在下一个和上一个片段之间,并在活动开始时将其放在最前面。

@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;
}

I'd suggest looking at the ViewPager class for this. 我建议为此查看ViewPager类。 It switches between fragments. 它在片段之间切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM