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. wingIDE设置支持中文注释

    用wingIDE快2年了,实在是受不了不支持中文,每次中文都报错,一个小逗号也要查很久,别说中文注释了,在网上找解决办法,原来这么简单! 下面,把破解放大和支持中文支持的方法备份下来,以便以后查看. ...

  2. windows下用php实现svn代码更新

    windows下的服务器 没有登录权限,如何从svn更新代码 用php页面,实现更新代码 $cmd = '"C:\Program Files\TortoiseSVN\bin\Tortoise ...

  3. 在AD的环境下,更改计算机名导致TFS,无法连接解决办法

    D:\vs2015>tf workspaces /collection:http://10.1.0.104:8080/tfs/dahua.adrms /updateComputerName:WI ...

  4. 利用opencv从USB摄像头获取图片

    由于opencv自带的VideoCapture函数直接从usb摄像头获取视频数据,所以用这个来作为实时的图像来源用于实体检测识别是很方便的. 1. 安装opencv 安装的步骤可以按照之前这个文章操作 ...

  5. -webkit-user-select

    -webkit-user-select: none;//不可选 -webkit-user-select: auto; //可复制

  6. java okhhtp下载学信网学籍信息

    学信网的登录有验证码,是那种计算数字或者汉字识别的,很难识别.最近连学籍信息和学历信息也换成图片了,常规的正则 css xpath都不能使. 下载图片,需要先登录,获取登陆后的cookie和学籍信息的 ...

  7. [scala] scala 函数 (⑦)

    1.scala 函数定义 2.scala 高阶函数 3.匿名函数 4.柯里化 import scala.math._ /** * @author xwolf * @date 2017-04-24 9: ...

  8. Spring boot配置log4j输出日志

    1. pom.xml文件中配置parent,版本选定[1.2.5.RELEASE] 关于为什么要选这个版本:我尝试使用[1.4.1.RELEASE],但该版本库里没有[spring-boot-star ...

  9. centos 7 安装 gcc-4.9.3.tar.gz

    由于编译新内核需要,更新了GCC编译器,自行获取文件,手动升级. 首先是获取文件:wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gc ...

  10. scala中Map和Tuple

    /** * Created by root * Description : Tuple and Map */ object MapTest { def main(args: Array[String] ...