The specified child already has a parent. You must call removeView() on the child's parent first

后端 未结 13 2155
余生分开走
余生分开走 2020-11-29 07:50

I create this post, because i am new at this, and i need a little help. I am doing a little exercise about a application you that put your name, and it returns \"hello (the

13条回答
  •  再見小時候
    2020-11-29 08:26

    In my case I was accidentally returning a child view from within Layout.onCreateView() as shown below:

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_reject, container, false);
    
        Button button = view.findViewById(R.id.some_button);
    
        return button; // <-- Problem is this
    }
    

    The solution was to return the parent view instead of the child view.

提交回复
热议问题