viewpager fragments not shown after the first-time

Reference: https://stackoverflow.com/questions/31607361/viewpager-fragments-not-shown-after-the-first-time

viewpager fragments not shown after the first-time:

solution

————————————————————————————————————————————-

You have to use ChildFragmentManager like below.

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    pagerAdapter = new PagerAdapter(getChildFragmentManager()); //here used child fragment manager 
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragmentA, container, false);

    vpPager = (ViewPager)view.findViewById(R.id.vpPager);
    vpPager.setOffscreenPageLimit(2);
    vpPager.setAdapter(pagerAdapter);
    vpPager.addOnPageChangeListener(this);

    return view;
}

 

 

Author: joker