小编qND*_*qND的帖子

使用FragmentStatePageAdapter为ViewPager保留片段的位置

我有一个包含TabLayout的活动,并为每个选项卡使用一个片段.作为回报,该片段包含与ViewPager一起使用的另一个片段.这是我的设置:

RoutineActivity.java

public class RoutineActivity extends AppCompatActivity {
private ArrayList<CategoryFragment> categories = new ArrayList<>();
private TabLayout tabs;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_routine);

    // Set the toolbar as the action bar and add the Up button
    Toolbar toolbar = findViewById(R.id.routine_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Get the intent and extract the string array
    Intent intent = getIntent();
    ArrayList<String> selected =
            intent.getStringArrayListExtra(SelectCategoriesActivity.EXTRA_CATEGORIES);

    // Set the TabLayout
    this.setTabs(selected);
}

// Set the tabs of the TabLayout given a list of tab names …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-viewpager fragmentstatepageradapter

2
推荐指数
1
解决办法
1281
查看次数