国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

RecyclerView索引溢出異常的解決方法

2019-10-22 18:12:54
字體:
來源:轉載
供稿:網友

使用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()    }  }}

調用時使用WrappedLinearLayoutManager代替LinearLayoutManager

val recyclerAdapter = RecyclerViewAdapter(activity)val manager = WrapContentLinearLayoutManager(context).apply { orientation = LinearLayoutManager.VERTICAL }val recyclerView = view.findViewById<RecyclerView>(R.id.recycler_view).apply {  layoutManager = manager  adapter = recyclerAdapter}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桂林市| 红原县| 巫山县| 贵德县| 奉贤区| 泌阳县| 富平县| 监利县| 烟台市| 太康县| 阜新| 南安市| 集安市| 平湖市| 安庆市| 洪泽县| 哈尔滨市| 黄平县| 阳江市| 鱼台县| 洛扎县| 高安市| 德安县| 曲周县| 岢岚县| 宜良县| 灯塔市| 乡城县| 磐石市| 株洲市| 晴隆县| 白玉县| 开封市| 卢湾区| 巴林左旗| 霍林郭勒市| 饶平县| 香格里拉县| 宜春市| 德阳市| 阳城县|