首页 > 其他 > 详细

替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's parent first.

时间:2014-07-21 08:03:23      阅读:381      评论:0      收藏:0      [点我收藏+]

在将一个fragment替换到一个frameLayout的时候报错:

code: transaction.replace(R.id.fragment_container, fragment2);

错误:  java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child‘s parent first.

 

原因:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

   //View newsView = inflater.inflate(R.layout.fragment_news, container);
        View newsView = inflater.inflate(R.layout.fragment_news, container,false);
        return newsView;
    }

 

出现此错误的根本问题是当前VIEW已经在别的View中,作为别的子View,现在又要将当前VIEW放在别的View中,就会抛出这类错误信息。

 

相同问题的其他文章:

http://www.cnblogs.com/shenbin/archive/2012/03/15/2398209.html

http://www.cnblogs.com/over140/archive/2013/06/06/3121354.html

替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's parent first.,布布扣,bubuko.com

替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's parent first.

原文:http://www.cnblogs.com/amosleaf/p/3857511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!