Replace Fragment inside a ViewPager

后端 未结 18 1653
别那么骄傲
别那么骄傲 2020-11-22 00:26

I\'m trying to use Fragment with a ViewPager using the FragmentPagerAdapter. What I\'m looking for to achieve is to replace a fragment, positioned

18条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 01:16

    after research i found solution with short code. first of all create a public instance on fragment and just remove your fragment on onSaveInstanceState if fragment not recreating on orientation change.

     @Override
    public void onSaveInstanceState(Bundle outState) {
        if (null != mCalFragment) {
            FragmentTransaction bt = getChildFragmentManager().beginTransaction();
            bt.remove(mFragment);
            bt.commit();
        }
        super.onSaveInstanceState(outState);
    }
    

提交回复
热议问题