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

首頁(yè) > 系統(tǒng) > Android > 正文

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

2019-12-12 01:01:28
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

使用RecyclerView過(guò)程中遇到異常:

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}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 遵义市| 华坪县| 禹城市| 垦利县| 多伦县| 乌兰县| 洪江市| 吉林省| 醴陵市| 云龙县| 新晃| 清水县| 麻栗坡县| 宿松县| 昭平县| 航空| 乃东县| 称多县| 石首市| 濉溪县| 海盐县| 河曲县| 潞西市| 灌云县| 克拉玛依市| 那坡县| 定襄县| 灵石县| 六枝特区| 宜兰县| 房产| 吴桥县| 西乌| 贵南县| 武鸣县| 东台市| 抚顺县| 阆中市| 全州县| 海口市| 江永县|