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

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

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

使用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)用時(shí)使用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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

绥化市| 宜黄县| 化隆| 汉寿县| 天水市| 邻水| 石屏县| 石嘴山市| 托里县| 西城区| 麻江县| 普定县| 汾阳市| 城市| 连城县| 宁远县| 通海县| 苍南县| 临桂县| 铅山县| 屯门区| 株洲县| 博爱县| 沙坪坝区| 玉溪市| 罗江县| 隆尧县| 即墨市| 库尔勒市| 兴隆县| 田阳县| 沛县| 青河县| 成安县| 和田县| 陇西县| 武穴市| 阜新| 水富县| 兴宁市| 高台县|