0

I'm using TabLayout from Android Design Support Library in my app.

I setup tabs using viewPager in activity's onCreate and they work well.

viewPager.setAdapter(
    new TabsAdapter(getSupportFragmentManager(),
        new TabInfo("Test1", Fragment1.newInstance()),
        new TabInfo("Test2", Fragment2.newInstance()),
        new TabInfo("Test3", Fragment3.newInstance())
    ));

tabs.setupWithViewPager(viewPager);

But sometimes, randomly when screen goes to sleep and I unlock the phone (tested on Moto G 2014, Android Lollipop) tabs just disappear.

It's bad, because I can't reproduce it on purpose.

Pavlo Zin
  • 762
  • 6
  • 25

1 Answers1

0

try using tabhost. It's a lot more stable. The code shown below is an example of a tabhost in a fragment with three child fragments. I use this kind of code myself and works perfectly

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    mTabHost = new FragmentTabHost(getActivity());
    mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.container);

    mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("tab1"),
            Tab1Fragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("tab2"),
            Tab2Fragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("tab3"),
            Tab3Fragment.class, null);
    return mTabHost;

}

VanpeltJ
  • 21
  • 7