使用RecyclerView中引发 java.lang.IllegalStateException: Cannot call this method while RecyclerView is com
2017-05-18 17:23
597 查看
出错原因
在适配器onBindViewHolder(….)方法里调用了notifyItemChanged(position),导致RecyclerView还没有渲染完滑动引发的错误代码
@Override public void onBindViewHolder(final ContentViewHolder holder, final int position) { ..... holder.et_Number.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { //TODO 问题就是我通过Log打印日志发现这个onBindViewHolder()加载数据时会一直渲染,导致notifyItemChanged(position)一直在循环,就会导致滑动时还没渲染完就调用这方法了 if(!b){ //焦点失去时刷新 notifyItemChanged(position); } }} ...... }
我的解决方法
int myPosition = -1; @Override public void onBindViewHolder(final ContentViewHolder holder, final int position) { ..... holder.et_Number.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { // TODO 在外面定义个变量myPosition ,当myPosition 不等于position就执行notifyItemChanged(position),这样的话每次就只执行一次了,再运行项目滑动失去焦点刷新就OK了 if(!b){ //焦点失去时刷新 if(myPosition == position) return; myPosition = position notifyItemChanged(position); } }} ...... }
相关文章推荐
- 关于cannot call this method while recyclerview is computing a layout or scrollin
- RecyclerView , IllegalStateException: Cannot call this method while RecyclerView is computing a layo
- Cannot call this method while RecyclerView is computing a layout or scrolling android.support.v7.wid
- 关于Recyclerview使用时的一个错误java.lang.NoSuchMethodError: No static method getMatrix(Landroid/view/View;)
- 关于Recyclerview使用时的一个错误java.lang.NoSuchMethodError: No static method getMatrix(Landroid/view/View;)
- java.lang.ClassCastException: android.widget.HeaderViewListAdapter cannot be cast to com.android.mms
- java.lang.SecurityException: Filter of class org.apache.catalina.ssi.SSIFilter is privileged and cannot be loaded by this web application
- java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting
- java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting
- java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting
- android Multiple markers at this line - The type java.lang.Class cannot be resolved. It is indirectl
- java.lang.IllegalStateException: Could not find a method false(View) in the activity class com.xuan
- Android Studio使用百度地图出现 java.lang.UnsatisfiedLinkError: Native method not found: com.baidu.mapapi.Mj.
- 解决spring使用动态代理类型转换失败的问题--java.lang.ClassCastException: com.sun.proxy.$Proxy$ cannot be cast to ...今天
- Android java.lang.IllegalStateException: Cannot start this animator on a detached view!
- android Multiple markers at this line - The type java.lang.Class cannot be resolved. It is indirectl
- android Multiple markers at this line - The type java.lang.Class cannot be resolved. It is indirectl
- java.lang.IllegalStateException: Cannot start this animator on a detached view!
- MyBatis与Spring MVC结合时,使用DAO注入出现:Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
- 使用Activity.isfinishing()解决java.lang.IllegalArgumentException: View not attached to window manager