fix bug
修复RecyclerView异常:java.lang.IndexOutOfBoundsException: Inconsistency detected
This commit is contained in:
@@ -55,7 +55,7 @@ class IPCReportWindow constructor(activity: Activity) : View.OnTouchListener{
|
||||
it.alpha = 0.9f
|
||||
}
|
||||
ipcReportAdapter = IPCReportAdapter()
|
||||
rvIPCReport.layoutManager = LinearLayoutManager(mActivity,
|
||||
rvIPCReport.layoutManager = WrapContentLinearLayoutManager(mActivity,
|
||||
LinearLayoutManager.VERTICAL,false)
|
||||
rvIPCReport.adapter = ipcReportAdapter
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class ReportListFloatWindow constructor(activity: Activity) : View.OnTouchListen
|
||||
it.alpha = 0.9f
|
||||
}
|
||||
reportListAdapter= ReportListAdapter(mActivity)
|
||||
rvReportList.layoutManager = LinearLayoutManager(mActivity,
|
||||
rvReportList.layoutManager = WrapContentLinearLayoutManager(mActivity,
|
||||
LinearLayoutManager.VERTICAL,false)
|
||||
rvReportList.adapter = reportListAdapter
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mogo.eagle.core.function.hmi.ui.setting
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
* @description fix java.lang.IndexOutOfBoundsException:检测到不一致。视图持有者适配器positionViewHolder无效
|
||||
* @since: 2022/6/7
|
||||
*/
|
||||
class WrapContentLinearLayoutManager : 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user