Why during the transition to the tabs, fragments are re-created? Here is my code:

public class TabFragmentU extends Fragment { ViewPager pager; PagerTabStrip tab_strp; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true); View x = inflater.inflate(R.layout.main_tab, null); tab_strp=(PagerTabStrip)x.findViewById(R.id.tab_strip); tab_strp.setTextColor(Color.WHITE); tab_strp.setTabIndicatorColor(Color.rgb(255, 255, 255)); tab_strp.setBackgroundColor(Color.rgb(255,88,6)); ma_pager_adapter adapter=new ma_pager_adapter(getChildFragmentManager()); pager=(ViewPager)x.findViewById(R.id.pager); pager.setAdapter(adapter); return x; } public class ma_pager_adapter extends FragmentPagerAdapter { public ma_pager_adapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { switch (i) { case 0: AllOrdersFragment t1 = new AllOrdersFragment();; return t1; case 1: ListNewsFragmentLocal t2 = new ListNewsFragmentLocal(); return t2; case 2: ListBisinessFragmentLocal t3 = new ListBisinessFragmentLocal(); return t3; } return null; } @Override public int getCount() { return 3; }//set the number of tabs @Override public CharSequence getPageTitle(int position) { Locale l = Locale.getDefault(); switch (position) { case 0 : return "Заявки"; case 1 : return "Новости"; case 2 : return "Бизнес"; } return null; } } } 
  • Please format the code before posting a question. - JuriySPb
  • Also observe the naming conventions - without underscores in the class name and with a capital letter - Yuriy SPb
  • On the subject itself - the fragment in the fragment is a bad idea in principle. Try changing the adapter class to FragmentStatePagerAdapter - YuriSPb
  • one
    This situation can be avoided by changing the fragment to activation and already stuffing the ViewPager into it - YuriySPb
  • one
    This is due to the default settings of the pager. Set it to setOffscreenPageLimit (2) - Yuriy SPb

0