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的更多相关文章

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

    在ViewPager中,用Fragment显示页面时,报错: java.lang.IllegalStateException: The specified child already has a pa ...

  2. android 异常信息The specified child already has a parent. You must call removeView() on the child's parent first. 的处理方法

    [Android异常信息]: The specified child already has a parent. You must call removeView() on the child's p ...

  3. 【Android异常】The specified child already has a parent. You must call removeView() on the child's parent first.

    错误信息: Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must ...

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

    在将一个fragment替换到一个frameLayout的时候报错: code: transaction.replace(R.id.fragment_container, fragment2); 错误 ...

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

    这个问题搞了我半天了,网上有很多人说需要找到该控件的parent后,让该parent 先remove需要添加的控件,然后在添加,如: if (view != null) { ViewGroup par ...

  6. Fragment+FragmentActivity出现The specified child already has a parent. You must call removeView() on the child's parent first.

    这个异常是出现在Fragment中的onCreateView方法中初始化布局时发生的. View view = inflater.inflate(R.layout.fragment3_layout, ...

  7. Child <- many-to-one ->Parent

    网上找到个描述的很精妙的例子 Child   <-   many-to-one   ->Parent         class   Child   {         private   ...

  8. Child extends Parent,可以得到什么?

    如果有Child extends Parent 1.子类可以调用父类无参的构造函数,子类的有参构造函数和是否调用父类的有参数的构造函数无必然联系 2.接口继承的时候,只能继承接口不能继承类,因为如果类 ...

  9. bug_ _fragment_“The specified child already has a parent. You must call removeView"的解决以及产生的原因

    这个异常的出现往往是因为非法使用了某些方法引起的. 从字面意思上是说这个特定的child已经有一个parent了,你必须在这个parent中首先调用removeView()方法,才能继续你的内容.这里 ...

随机推荐

  1. VVDocumenter规范注释生成器

    下载地址:https://github.com/onevcat/VVDocumenter-Xcode PS:Xcode 8.0 默认支持了,但是是关闭状态,需要在终端输入如下命令开启,然后重启 Xco ...

  2. Eclipse + PyDev 快捷键

    ●多行缩进(减少缩进):tab/shift+tab ●复制行: Ctrl+Alt+方向键'↓' ●删除行:Ctrl+d ●自动完成:Alt+/  ●注释:Ctrl+/ ●窗口最大小:Ctrl+m == ...

  3. struts2危险漏洞解决方法

    原创,bgy编写.2013-07-24 前文: 随着苹果开发者网站的沦陷,已经曝光一周的Apache Struts2漏洞再次成为热门话题,今天有消息称由于该漏洞被利用,淘宝的数据库已经被盗,尽管淘宝官 ...

  4. QT运行出错:QObject::connect: Parentheses expected以及QObject::connect: No such slot ***

    我在QGraphicsScene子类中添加了item的弹出菜单,并连接Action到槽函数,结果槽函数不起作用,输出:QObject::connect: No such slot ***  C++ C ...

  5. Spring中的类型转换与数据绑定(PropertyEditor、ConversionService、Data Binding、Formatter)

    Spring早期使用PropertyEditor进行Object与String的转换.到Spring 3后,Spring提供了统一的ConversionService API和强类型的Converte ...

  6. SpringBoot------文件上传

    1.pom.xml引入依赖配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http ...

  7. PMP用语集

    AC actual cost 实际成本 ACWP actual cost of work performed 已完工作实际成本 BAC budget at completion 完工预算 BCWP b ...

  8. 随笔 -- NIO -- 相关 -- 系统概述

    .打开Selector .打开ServerSocketChannel .获取与此Channel关联的ServerSocket并绑定地址 .设置Channel为非阻塞 .将Channel注册到Selec ...

  9. RF判断列表、字典、整数、字符串类型是否相同方法

      ${d} create list shk shsh${w} create list ${e} evaluate type(${d}) ${t} evaluate type(${w}) should ...

  10. log4net日志的简单配置

    说起来log4net,我一直都知道这个的存在,但实际在项目中还真是没有去自己写过的那,这一次我在项目完成后并没有着急下一个项目的开始,于是突然想起来是否添加一个日志的编写,于是开始了log4net的总 ...