The specified child already has a parent..."错误
来源:互联网 发布:youtube什么软件 编辑:程序博客网 时间:2024/05/22 10:46
当我们调用ViewGroup的addView()方法时
public void addView(View child) {
addView(child, -1);
}最终会调用addViewInLayout()方法
private void addViewInner(View child, int index, LayoutParams params, boolean preventRequestLayout) { if (mTransition != null) { // Don't prevent other add transitions from completing, but cancel remove // transitions to let them complete the process before we add to the container mTransition.cancel(LayoutTransition.DISAPPEARING); } if (child.getParent() != null) { throw new IllegalStateException("The specified child already has a parent. " + "You must call removeView() on the child's parent first."); } ... if (index < 0) { index = mChildrenCount; } ...}
由此可知,产生这个错误的原因是child.getParent() != null,即当前View的parent不为空,之前有被加到过ViewGroup里面
解决办法:调用父view的removeAllViews()或者removeView()方法。如果不知道父view,可以使用这个方法
<pre name="code" class="java">public static void removeParent(View v){ ViewParent parent = v.getParent(); if(parent instanceof ViewGroup){ ViewGroup group=(ViewGroup) parent; group.removeView(v); } }
0 0
- The specified child already has a parent错误
- The specified child already has a parent错误
- The specified child already has a parent错误解决办法
- The specified child already has a parent..."错误
- 【错误】The specified child already has a parent.
- The specified child already has a parent.
- The specified child already has a parent
- The specified child already has a parent
- The specified child already has a parent
- The specified child already has a parent. You must call removeView() on the child's parent first.错误
- Fragment error:The specified child already has a parent.
- IllegalStateException: The specified child already has a parent问题解决办法
- AlertDialog异常The specified child already has a parent. ..解决方法
- ViewPager Fragment IllegalStateException: The specified child already has a parent
- IllegalStateException :the specified child already has a parent
- IllegalStateException: The specified child already has a parent问题解决办法
- java.lang.IllegalStateException: The specified child already has a parent.
- Android The specified child already has a parent.解决方法
- 谈谈javaweb中的重定向
- 代码片段-设计模式
- ORACLE 管理undo
- js实现动态显示时间(setInterval())
- ListView下拉刷新框架使用
- The specified child already has a parent..."错误
- 汇编基础
- Cocos2dx-3.x触摸事件之实现人机交互(一)
- const有哪些作用
- 寄存器(CPU里面的内存,CPU里面的存储器)
- 2016.7.15
- 寄存器(内存访问)
- 小算法--卡片问题
- 第一个程序