Error inflating class fragment - duplicate id/illegalargumentexception?

后端 未结 7 915
梦毁少年i
梦毁少年i 2020-12-02 17:05

I\'m trying make an app that I\'m building take a search term from the main activity, return results, and then have the results be clickable such that a detail could be view

7条回答
  •  猫巷女王i
    2020-12-02 18:00

    You can extend you fragment (which you load in xml) from XmlFragment. It handles parent FragmentManager and removes itself.

    public class XmlFragment extends BaseFragment {
    
        @Override
        public void onDestroyView() {
            Fragment parentFragment = getParentFragment();
            FragmentManager manager;
            if (parentFragment != null) {
                // If parent is another fragment, then this fragment is nested
                manager = parentFragment.getChildFragmentManager();
            } else {
                // This fragment is placed into activity
                manager = getActivity().getSupportFragmentManager();
            }
            manager.beginTransaction().remove(this).commitAllowingStateLoss();
            super.onDestroyView();
        }
    }
    

提交回复
热议问题