Android Fragment no view found for ID?

前端 未结 30 2433
逝去的感伤
逝去的感伤 2020-11-22 05:33

I have a fragment I am trying to add into a view.

FragmentManager fragMgr=getSupportFragmentManager();
feed_parser_activity content = (feed_parser_activity)f         


        
30条回答
  •  暖寄归人
    2020-11-22 06:08

    If you are trying to replace a fragment within a fragment with the fragmentManager but you are not inflating the parent fragment that can cause an issue.

    In BaseFragment.java OnCreateView:

    if (savedInstanceState == null) {
                getFragmentManager().beginTransaction()
                        .replace(R.id.container, new DifferentFragment())
                        .commit();
            }
    
    return super.onCreateView(inflater, container, savedInstanceState);
    

    Replace super.onCreateView(inflater, container, savedInstanceState); with inflating the correct layout for the fragment:

            return inflater.inflate(R.layout.base_fragment, container, false);
    

提交回复
热议问题