The specified child already has a parent.You must call removeView() on the child's parent first问题
来源:互联网 发布:仓管员用什么软件 编辑:程序博客网 时间:2024/06/04 01:10
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first问题解决
ViewPaper动态加载布局时出现如下错误:
```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:3936) at android.view.ViewGroup.addView(ViewGroup.java:3786) at android.support.v4.view.ViewPager.addView(ViewPager.java:1413) at android.view.ViewGroup.addView(ViewGroup.java:3727) at android.view.ViewGroup.addView(ViewGroup.java:3700) at com.zz.quicknews.fragment.HomeFragment$HomePagerAdapter.instantiateItem(HomeFragment.java:81) at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:943) at android.support.v4.view.ViewPager.populate(ViewPager.java:1157) at android.support.v4.view.ViewPager.populate(ViewPager.java:1025) at android.support.v4.view.ViewPager$3.run(ViewPager.java:254) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:549) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
以上代码存在反复添加同一个view1的情况,而
这违反了AdapterView中The specified child already has a parent(已有父控件的子控件再次添加父控件)。
因此,可以按如下更改:
for (int i=0;i<tabTitleList.length;i++){ mTabLayout.addTab(mTabLayout.newTab().setText(tabTitleList[i])); View view1=inflater.inflate(R.layout.item_gridview,null); mViewList.add(view1); }
更改后即可正常工作。
0 0
- 问题: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
- 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.
- 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
- js数组与字符串的相互转化
- Android NDK环境搭建及JNI开发java和C的相互调用的基本介绍
- 非递归的fib与找出无重复的两个数
- Java对Excel(03,07)进行上传、解析、验证、入库
- HDU 1233 还是畅通工程 [最小生成树]
- The specified child already has a parent.You must call removeView() on the child's parent first问题
- 第一个博文
- yii2获取用户get,post参数
- Android Launcher加载so库问题
- Android WheelView自定义续更
- Odd Even Linked List
- UIApplicationMain
- 【数据结构】线性表的顺序存储完整程序
- Android常见异常总结