I have InnerFragment containing RecyclerView, inside MainFragment which is added to ViewPager. When MainFragment gets created while swiping OnResume is called multiple times
Adding MainFragment in ViewPager
//Assigning Adapter in ViewPager
mViewPager.setAdapter(new MyAdapter(getFragmentManager()));
//getItem inside MyAdaper
public Fragment getItem(int position){
return MainFragment.newInstance(position);
}
Adding InnerFragment in MainFragment
getChildFragmentManager().beginTransaction().add(R.id.framelayoutID, InnerFragment.newInstance()).commit();
when adding fragment, use replace() instead of add()
before
getChildFragmentManager().beginTransaction().add(R.id.framelayoutID, InnerFragment.newInstance()).commit();
after
getChildFragmentManager().beginTransaction().replace(R.id.framelayoutID, InnerFragment.newInstance()).commit();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With