使用RecyclerView中引发 java.lang.IllegalStateException: Cannot call this method while RecyclerView is com
来源:互联网 发布:ps4数据库损坏 编辑:程序博客网 时间:2024/05/16 06:28
出错原因
在适配器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); }}} ...... }
阅读全文
1 0
- 使用RecyclerView中引发 java.lang.IllegalStateException: Cannot call this method while RecyclerView is com
- RecyclerView , IllegalStateException: Cannot call this method while RecyclerView is computing a layo
- Cannot call this method while RecyclerView is computing a layout or scrolling
- 关于cannot call this method while recyclerview is computing a layout or scrollin
- [AS尝龟]Recyclerview的OnCreatViewHolder报错:java.lang.IllegalStateException
- 异常java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'xxx' method
- nested exception is java.lang.IllegalStateException: Encountered invalid @Scheduled method
- nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map ***
- 关于Recyclerview使用时的一个错误java.lang.NoSuchMethodError: No static method getMatrix(Landroid/view/View;)
- 关于Recyclerview使用时的一个错误java.lang.NoSuchMethodError: No static method getMatrix(Landroid/view/View;)
- Android RecyclerView 报错:java.lang.IllegalStateException: The specified child already has a...
- 关于RecyclerView的java.lang.IllegalStateException: The specified child already has a parent. You must c
- Fragment中使用出现的java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed错误
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- 解决struts/spring偶尔出现java.lang.IllegalStateException: Cannot call sendRedirect() after the response的问题
- java.lang.IllegalStateException: You cannot call onTextChanged with a non filterable adapter
- JSTL中fmt标签详解
- MailBee.NET Objects发送电子邮件(SMTP)教程七:添加多个附件
- 机器学习中过拟合问题
- 阿里云ECS Centos开启ipv6支持
- ECMAScript 6(12)函数的扩展(1)——函数参数的默认值之详细解析
- 使用RecyclerView中引发 java.lang.IllegalStateException: Cannot call this method while RecyclerView is com
- 在二叉查找树中插入节点
- redis 相关命令
- 【Android7.1.2源码解析系列】实战分析init.rc文件
- Kotlin学习!!!此帖有点火
- JVM调优总结(七)-典型配置举例1
- Activity的生命周期
- EOJ-3218 思维 + STL
- 验证码/密码按位分割输入框