国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌拉特前旗| 房产| 雷山县| 红河县| 临泽县| 泸定县| 朝阳市| 百色市| 泾阳县| 霍州市| 固阳县| 宜兴市| 涟源市| 江西省| 于田县| 莱阳市| 定南县| 临城县| 十堰市| 高陵县| 江孜县| 平南县| 西乌珠穆沁旗| 绥阳县| 哈巴河县| 新乡县| 丹棱县| 达日县| 南乐县| 锡林浩特市| 泰州市| 赤峰市| 汶川县| 天镇县| 贵港市| 和田市| 香港| 大方县| 金平| 琼海市| 揭东县|