首页 > 其他 > 详细

Call removeView() on the child's parent first

时间:2015-04-10 21:49:10      阅读:318      评论:0      收藏:0      [点我收藏+]

extends:http://stackoverflow.com/questions/6526874/call-removeview-on-the-childs-parent-first

 

Exception:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child‘s parent first.
           at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
           at android.view.ViewGroup.addView(ViewGroup.java:1871)
           at android.view.ViewGroup.addView(ViewGroup.java:1828)
           at android.view.ViewGroup.addView(ViewGroup.java:1808)
Solution:

((ViewGroup)scrollChildLayout.getParent()).removeView(scrollChildLayout); 

Use the child element to get a reference to the parent. Cast the parent to a ViewGroup so that you get access to the removeView method and use that.
     LinearLayout layout = initLayout();
        for (int i = 0; i < items.size(); i++) { 
            View view = items.get(i);
            ((ViewGroup) view.getParent()).removeView(view);
            layout.addView(view, lpLabel);
        }
        mLayout.addView(layout);

 

Call removeView() on the child's parent first

原文:http://www.cnblogs.com/niray/p/4415516.html

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