最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2018年04月17日 09:22:18   作者:phantomvk  
本篇文章主要介紹了RecyclerView索引溢出異常的解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

調(diào)用時使用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
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

依安县| 建湖县| 阳春市| 额敏县| 楚雄市| 图们市| 乌拉特前旗| 保康县| 肃南| 五指山市| 淳化县| 铜陵市| 丰顺县| 大埔区| 本溪市| 博乐市| 双城市| 辽源市| 古田县| 绿春县| 昌吉市| 得荣县| 云林县| 社会| 建平县| 咸宁市| 冷水江市| 若羌县| 神木县| 仁布县| 类乌齐县| 阆中市| 贵阳市| 余庆县| 大石桥市| 阿图什市| 教育| 芒康县| 昆明市| 沁源县| 鄂州市|