关于向父view添加相同的view问题!The specified child already has a parent. You must call removeView() on the chil
来源:互联网 发布:misia 知乎 编辑:程序博客网 时间:2024/06/04 18:07
01
02
03
04
for
(
int
i=
0
; i <
5
; i++){
View view = LayoutInflater.from(
this
).inflate(R.layout.item_bg,
null
);
lin_item.addView(view);
}
lin_item为一个LinearLayout,把view动态加到这个lin_item中,但是只能加进一条数据。。。要不然就报07-28 22:03:49.360: ERROR/AndroidRuntime(1403): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
这个异常,我知道view为同一个,所以会产生这种异常。但是我就是要这样动态的加入view到lin_item里啊。。有没什么办法呢。。
01
02
03
04
05
06
View view1 = LayoutInflater.from(
this
).inflate(R.layout.lin_item_ev,
null
);
View view2 = LayoutInflater.from(
this
).inflate(R.layout.lin_item_ev,
null
);
View view3 = LayoutInflater.from(
this
).inflate(R.layout.lin_item_ev,
null
);
lin_item.addView(view1);
lin_item.addView(view2);
lin_item.addView(view3);
如果这样写就没问题了。。但是还是同一个layout啊。。。我知道原因的,但有没办法可以像上面那样动态的生成view并加到linearLayout里。。。
以上同样情况。。同一个view不能让父view addview 2次,所以解决办法是:
LinearLayout ll = (LinearLayout) findViewById(R.id.ll); dots = new ImageView[imageColors1.length]; // 循环取得小点图片 for (int i = 0; i < imageColors1.length; i++) { dots[i] = (ImageView) LayoutInflater.from(this).inflate(R.layout.dot, null); dots[i].setEnabled(true);// 都设为灰色 ll.addView(dots[i]); }
0 0
- 关于向父view添加相同的view问题!The specified child already has a parent. You must call removeView() on the chil
- The specified child already has a parent. You must call removeView() on the chil
- 自定义Dialog,第二次点击item报The specified child already has a parent. You must call removeView() on the chil
- 问题:The specified child already has a parent. You must call removeView() on the child's parent first.
- The specified child already has a parent.You must call removeView() on the child's parent first问题
- The specified child already has a parent. You must call removeView() on the child's parent first问题
- 解决The specified child already has a parent. You must call removeView() on the child's parent first问题
- 关于异常“The specified child already has a parent. You must call removeView"的解决
- The specified child already has a parent. You must call removeView() on the
- 关于一个错误的记录:The specified child already has a parent. You must call removeView() on the child's parent
- The specified child already has a parent. You must call removeView() on the child's parent first.
- 二、The specified child already has a parent. You must call removeView() on the child's parent first.
- The specified child already has a parent. You must call removeView() on the child's parent first
- The specified child already has a parent. You must call removeView() on the child's parent first
- The specified child already has a parent. You must call removeView() on the child's parent first.
- The specified child already has a parent. You must call removeView() on the child's parent first.
- The specified child already has a parent. You must call removeView() on the child's parent first
- The specified child already has a parent. You must call removeView() on the child's parent first.
- JavaSE_IO流_文件+递归+Properties
- Hadoop 2.0 NameNode HA和Federation实践
- SQL Server 2014 BI新特性(二)结合Data Explorer和GeoFlow进行数据分析
- 安桌HttpURLConnection错误解决
- SQL Server 2014新特性探秘(1)-内存数据库
- 关于向父view添加相同的view问题!The specified child already has a parent. You must call removeView() on the chil
- windows命令行下的vim vimforcmd
- 使用C++语言编写多线程程序的速成代码
- 使用Struts2标签,s:if判断遇见问题
- 浏览器保存网页的四种方式
- ucos代码裁剪
- tomcat版本查询
- 详解EBS接口开发之销售订单导入
- Windows开发功能小集!UDP/TCP开发步骤