Fragment lifecycle - which method is called upon show / hide?

前端 未结 11 1033
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 08:31

I am using the following method to switch between Fragments (in my NavigationDrawer) by showing / hiding them.

protected void showFragment(int container, Fra         


        
11条回答
  •  感情败类
    2020-12-04 09:11

    You can use 'onCreateView'(or 'onActivityCreated') and 'onHiddenChanged'. Use 'onCreateView' for first show and use 'onHiddenChanged' for later. 'setMenuVisibility' is not called on transaction control.

    @Override
    public View OnCreateView() {
       // fragment will show first
    }
    
    @Override
    public void onHiddenChanged(boolean hidden) {
        if (!hidden) {
            // fragment will show 
        }
        else {
            // fragment will hide
        }
    }
    

提交回复
热议问题