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

来源:互联网 发布:js头像上传功能插件 编辑:程序博客网 时间:2024/04/29 08:12

学习android 的 fragment时遇到The specified child already has a parent. You must call removeView() on the child's parent first的错误,

提示已经有父容器,通过调试一直是fragmentTransaction.commit();的错误,后来知道是fragment中的问题

View view = inflater.inflate(R.layout.activity_content, container);

原来这里默认绑定了一个container的容器,所以调用commit时提示已经有了父容器,只需改成

View view = inflater.inflate(R.layout.activity_content, container, false);

默认不绑定就可以了

0 0
原创粉丝点击