RecyclerView索引溢出异常的解决方法-创新互联-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

RecyclerView索引溢出异常的解决方法-创新互联

使用RecyclerView过程中遇到异常:

成都创新互联公司专注于滦南企业网站建设,响应式网站开发,商城网站建设。滦南网站建设公司,为滦南等地区提供建站服务。全流程按需定制网站,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder


继承并重写LinearLayoutManager.onLayoutChildren()方法

class WrappedLinearLayoutManager : LinearLayoutManager {

  constructor(context: Context) : super(context)

  constructor(context: Context, orientation: Int, reverseLayout: Boolean) : super(context, orientation, reverseLayout)

  constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)

  override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State) {
    try {
      super.onLayoutChildren(recycler, state)
    } catch (e: IndexOutOfBoundsException) {
      e.printStackTrace()
    }
  }
}


本文标题:RecyclerView索引溢出异常的解决方法-创新互联
转载来于:http://kswsj.cn/article/dhiioh.html

其他资讯