RecyclerView The specified child already has a parent. You must call removeView() on the child's pa
来源:互联网 发布:淘宝卖家怎么处理违规 编辑:程序博客网 时间:2024/06/05 21:07
今天在做一个小列表的时候,本来以为分分钟解决的事遇到这个错误
定位到 at android.support.v7.widget.RecyclerView$5.addView(RecyclerView.java:638)
就是addView的代码 此方法是ViewGroup的,那必然是item是有parent导致的看了半天
@Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new MyViewHolder(LayoutInflater.from(context).inflate(layoutId, parent)); }
也就这inflate方法可能有问题,因为在这里加载的item嘛,一看方法有个重载的方法
inflate(@android.support.annotation.LayoutRes int resource, @android.support.annotation.Nullable android.view.ViewGroup root, boolean attachToRoot)再看刚用的方法inflate(@LayoutRes int resource, @Nullable ViewGroup root)
public View inflate(@LayoutRes int resource, @Nullable ViewGroup root) { return inflate(resource, root, root != null); }奶奶的原来不传 attachToRoot 并且root不为null 直接传的true,直接把parent当成item的爸爸。这尼玛。。。
果断换成
@Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new MyViewHolder(LayoutInflater.from(context).inflate(layoutId, parent,false)); }
然后就可以了
0 0
- RecyclerView The specified child already has a parent. You must call removeView() on the child's pa
- 替换Fragment 报错 The specified child already has a parent. You must call removeView() on the child's pa
- viewpage:The specified child already has a parent. " + "You must call removeView() on the child's pa
- 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.问解决
- 数据结构(6)--逆波兰计算器的运用
- bootstrap 上传图片插件 file-input 的简单使用
- 【poj1804】 Brainman
- <Android 应用 之路> MPAndroidChart~BarChart
- 根据天数计算具体日期
- RecyclerView The specified child already has a parent. You must call removeView() on the child's pa
- TCP HTTP UDP 区别(丢掉的计算机网络找回来)
- ubuntu16.04下配置Qt+OpenCV开发环境
- 深入理解Android卷二 第6章 深入理解ActivityManagerService
- 描述符的总结
- 自己动手写js分享插件 [支持https] (QQ空间,微信,新浪微博。。。)
- 第27篇 linux下布署vpn
- 1012. The Best Rank (25)
- if语句