RcyclerView踩过的坑

2017-08-15  本文已影响18人  奋飞的蜗牛ing

1、The specified child already has a parent. You must call removeView() on the child's parent first.

分析原因:在onCreateViewHolder(ViewGroup parent, int viewType) 中使用View view = View.inflate(mContext, R.layout.item_second_homepage_search_conditions, parent); 默认是绑定的。

解决方案:使用View view = LayoutInflater.from(mContext).inflate(R.layout.item_second_homepage_search_conditions, parent,false); 必须指定为false。

2、notifyDataSetChanged()无效,没有调用onBindViewHolder()和onCreateViewHolder()方法。

分析原因:使用notifyDataSetChanged,必须保证拥有该adapter的对象必须是同一个。当时的错误:在resume()中都会去new一个card,该card中会去new adapter。

解决方案:该变new card的流程,放在其它生命周期中。

上一篇 下一篇

猜你喜欢

热点阅读