新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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://www.wjwzjz.com/article/dhiioh.html
在线咨询
服务热线
服务热线:028-86922220
TOP