最近遇到一个很让人头疼的问题,使用viewpager动态添加页面或者删除页面时出现了问题(java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first),在stackoverflow上找到了解决办法。(http://stackoverflow.com/questions/22936886/java-lang-illegalstateexception-while-using-viewpager-in-android)
原文是:
the problem is that in your adapters method instantiateItem
you call container.addView(v);
but every View
can have only one parent,
so it can be added only one time to a container via addView(...)
.
When you open the popup the first time, everything works, because v
doesn't have a parent that time. But when you open your popupwinow the second time,
it adds the view again to the container. That cerates the error.
Try to destroy the view if you close the popup view or remove all children views from it withcontainer.removeAllViews()
解决办法是在instantiateItem中使用如下方式:
ViewGroup parent = (ViewGroup) v.getParent();
if (parent != null) {
parent.removeAllViews();
}
container.addView(v);
中间很多次尝试已经接近答案,但是习惯性的去把v.getParent()强制转化为view,view没有removeView()方法,以至于放弃了这种方法,以后要多思考,想到的解决办法如果完全不是自己想要的结果,一定要再检查一遍,很有可能是某个小地方没注意。
原帖地址:http://blog.csdn.net/mengliluohua_151/article/details/41866137
相关推荐
IllegalStateException: The specified child already has a parent.我的博客中有文章讲解
纠结了半天的 java.lang.IllegalStateException: getOutputStream() has already。这个问题困扰了半天,在网上查阅了大量资料 出这个错误一般就是下面2个.....
NULL 博文链接:https://hw1287789687.iteye.com/blog/1925191
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but...
异常:Caused by: java.lang.IllegalStateException: Method has too many Body parameters Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract ...
NULL 博文链接:https://anminer.iteye.com/blog/845067
1. java.lang.IllegalStateException: No wrapped connection. 2.java.lang.IllegalStateException: Adapter is detached. 原因: 1.单线程一次执行一个请求可以正常执行,如果使用多线程,同时执行多个请求时就会...
解决java.lang.IllegalStateException: unread block data的架包
spring 总的概述。。。入门好教程~~~~~~~~~~~~~
这个存储库提供了一种在处理片段传输和后台任务时避免“java.lang.IllegalStateException:Can not perform this action after onSaveInstanceState”的方法。 您可以在的非常权威的阅读有关该问题和可能的解决方案...
从excel导入数据到datawindow-转载
各种数据库在JDBC中的连接方法.及在struts与hibernate中的配置..
Android ListView 异常解决办法: ...10-26 18:30:45.085: E/AndroidRuntime(7323): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. M
因工作的缘故,有机会接触了Java本地方法调用(JNI)。本文中记下了初试JNI的过程和一点点体会。 使用Java的JNI调用C/C++的动态联结库有个固定的步骤,下面将以一个最简单的HelloWorld例子程序来说明调用过程。...
今天公司springboot项目准备部署到...java.lang.IllegalStateException: 启动子级时出错 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720) at org.apache.catalina.core.Con
SteganoImage 1.0 绿色版
java dubbo admin 2.5.3 + jdk 1.7 亲试 好用 ... java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
里面包含了java通过xfire访问webservice用到的jar包,已经打包好了
主要介绍了java 实现websocket的两种方式实例详解,一种使用tomcat的websocket实现,一种使用spring的websocket,本文通过代码给大家介绍的非常详细,需要的朋友可以参考下
Jnative1.4_java调用动态库所需jar,里面包含了一个可以测试的动态库,可以自己拿下来玩玩。