0

Good Afternoon, I have an activity that contains 4 Fragments using tab layout, when I initialize the Activity only two fragments are initialized at a time, for example while I am in the first fragment, Fragment 1 and 2 are initialized, when I slide to 2 it initializes the third and then 2 and 3 are initialized and the first is destroyed, is it possible for everyone to be initialized together?

this is my Adapter:

public class TabManualAdapter extends FragmentStatePagerAdapter {


private String[] tituloTabsManual = {"TAB1","TAB2","TAB3","TAB4"};



public TabManualAdapter(@NonNull FragmentManager fm) {
    super(fm);
}

@NonNull
@Override
public Fragment getItem(int position) {
    Fragment fragment = null;
    switch (position){
        case 0 :
            fragment = new Fragment1();
            break;
        case 1 :
            fragment = new Fragment2();
            break;

        case 2:
            fragment = new Fragment3();
            break;

        case 3:
            fragment = new Fragment4();
            break;
    }
    return fragment;
}

@Override
public int getCount() {
    return tituloTabsManual.length;
}

@Nullable
@Override
public CharSequence getPageTitle(int position) {
    return tituloTabsManual[position];
}

}

and Activity Code:

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

  
    SlidingTabLayout slidingTabLayout = findViewById(R.id.stl_tabs_manual);
    viewPager =  findViewById(R.id.vp_pagina_manual);
    viewPager.setPageTransformer(true,new ZoomOutPageTransformer());

  

    slidingTabLayout.setSelectedIndicatorColors(ContextCompat.getColor(this,R.color.colorPrimary));
    slidingTabLayout.setDistributeEvenly(true);
    slidingTabLayout.setBackgroundColor( ContextCompat.getColor( this, R.color.black ) );

    TabManualAdapter tabManualAdapter = new TabManualAdapter(getSupportFragmentManager());
    viewPager.setAdapter(tabManualAdapter);

    CircleIndicator indicator =  findViewById(R.id.indicator);
    indicator.setViewPager(viewPager);

    slidingTabLayout.setViewPager(viewPager);

0 Answers0