OnResume() not called in Fragment using tabLayout and ViewPager

前端 未结 2 491
后悔当初
后悔当初 2020-12-10 13:40

i\'m developing an app using tabLayout.

I\'ve a problem: When I try to reactivate a Fragment, the method OnResume is non calle

相关标签:
2条回答
  • 2020-12-10 14:18

    The accepted answer did not work for me. However, I found a solution to the problem.

    Just initialise your FragmentStatePagerAdapter with the following constructor:

    public MyPagerAdapter(FragmentManager fm, int behaviour) {
        super(fm, behaviour);
    }
    

    like this :

    MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getChildFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    
    0 讨论(0)
  • 2020-12-10 14:20

    I've solved the problem. I use setUserVisibleHint(boolean isVisibileToUser) instead onResume(). Like this:

     @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser) {
            init();
        } else {
    
        }
    }
    

    Thank you all!

    0 讨论(0)
提交回复
热议问题