Getting reference to nested fragment from FragmentTabHost

后端 未结 4 510
走了就别回头了
走了就别回头了 2021-02-07 05:11

In my application, I use an Activity which holds one Fragment with FragmentTabHost and hence all its tabs are nested Fragments

4条回答
  •  情深已故
    2021-02-07 05:58

    Above solutions are also working but I have one more easy solution,

     @Override
    public void onTabChanged(final String tabId) {
    
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
    
                mFragment = getChildFragmentManager().findFragmentByTag("Tagname");
            }
        },1000);
    }
    

    Here you have to implement FragmentTabHost.onTabChangeListener We have kept a second delay in fetching fragment from the childFragmentManager.

    Note : You need to cast mFragment which fragment you have used.

提交回复
热议问题