The specified child already has a parent. You must call removeView() on the child's parent first
来源:互联网 发布:融合网络 英文 编辑:程序博客网 时间:2024/03/29 19:30
最近在项目中使用Fragment,在某个Fragment中使用了ViewPager,ViewPager每一页的内容是一个GridView,在初始化Fragment的时候,inflater了一个view,然后让这个view作为viewPager的Parent,之后往ViewPager里加入views,生成每个view的代码如下:
private View newPerPage(){
LayoutInflater inflater =(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.per_page,null);
GridView gridview = (GridView) layout.findViewById(R.id.per_page);
GridAdapter gridAdapter = new GridAdapter(activity);
gridview.setAdapter(gridAdapter);
gridview.setOnTouchListener(forbidenScroll());
gridview.setOnItemClickListener(clickFuncItem());
return gridview;
}
注意蓝色部分,这时候滑动ViewPager的时候就会产生标题所示的异常。
原因很简单了,gridview有了两个Parent,一个是初始化Fragment的inflater的view,一个是在newPerPage()时inflater的一个view。解决的办法其实很简单。代码如下:
private View newPerPage(){
LayoutInflater inflater =(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.per_page,null);
GridView gridview = (GridView) layout.findViewById(R.id.per_page);
GridAdapter gridAdapter = new GridAdapter(activity);
gridview.setAdapter(gridAdapter);
gridview.setOnTouchListener(forbidenScroll());
gridview.setOnItemClickListener(clickFuncItem());
return layout;
}
直接返回gridview的父类就可以了。
- 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.
- SQL语句(mysql为模板)
- 第一次程序设计作业
- 第二堂作业
- C# 无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。
- obj-c UIAlertView
- The specified child already has a parent. You must call removeView() on the child's parent first
- 注册动态链接库(dll文件),提示找不到入口点
- IP定位
- 手机网站wap2.0版与html5触屏版有什么区别?
- 第二次程序设计上机报告
- Linux下shell脚本手动执行和放在crontab中自动执行的结果不一样
- HTTP协议之状态码详解
- 我的新浪博客
- eclipse 快捷键