I am using ViewPager with PagerTabStrip in fragment A and everything is working fine. Elements are filled. ... until I replace A with B , and then replace B with A again.
xml snippet :
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v4.view.PagerTabStrip android:id="@+id/pager_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#222222" android:textColor="@color/blue" /> </android.support.v4.view.ViewPager>
Debuggin shows that after the second replacement, getItem(int position) never reached in the FragmentPagerAdapter . Tabs are empty.
Tab Adapter :
private class ChannelsFragmentPagerAdapter extends FragmentPagerAdapter { final int PAGE_COUNT = dataChannelsList.size(); public ChannelsFragmentPagerAdapter(FragmentManager fm) { super(fm); } @Override public int getCount() { return PAGE_COUNT; } @Override public CharSequence getPageTitle(int position) { return dataChannelsList.get(position).getLang(); } @Override public Fragment getItem(int position) {
But again , if I turn the phone when the tabs are empty, they suddenly recreate in the usual usual way.
adapter call in onCreateView () :
View rootView = inflater.inflate(R.layout.fragment_channels,container, false); ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.pager); viewPager.setAdapter(new ChannelsFragmentPagerAdapter(getFragmentManager()));
Any ideas that cause this behavior? Appreciate any help with explanation.
Tell me if you need any more code.
source share