ChatGPT给了三种方案
我用了第一种
override fun onBindViewHolder(
holder: RecyclerView.ViewHolder, position: Int, payloads: MutableList<Any>
) {
when (getItemViewType(position)) {
ITEM_VIEW_TYPE -> {
val item = mModel.mListDatas[position] as ReadAfterBean
if (holder !is ReadAfterSentenceHolder) {
return
}
holder.binding.apply {
for (payload in payloads) {
when (payload) {
in listOf("localReadsSentenceData") -> updateSentenceView(
item.localReadsSentenceData, this, position
)
in listOf("recordStatus") -> updateChangeStatus(
item.recordStatus, this, position
)
in listOf("localDialogActionData") -> updateActionData(
item.localDialogActionData, this, position
)
in listOf("playingData") -> updateSentencePlayingState(
item.playingData, this
)
}
}
}
}
BOTTOM_STATUS_VIEW_TYPE -> {
}
else -> throw IllegalArgumentException("Invalid view type")
}
super.onBindViewHolder(holder, position, payloads)
}
重写 holder: RecyclerView.ViewHolder, position: Int, payloads: MutableList<Any>
三个参数的方案
payloads 这个 我从未用过。但是是真好用
这个方法重写后不要删除原来的 onBindViewHolder 还是照常设置数据,
当遇到频繁要刷新的数据时。
在需要频繁更新的数据中去设置。
if (mModel.mListDatas[position] is ReadAfterBean) {
val readAfterBean = mModel.mListDatas[position] as ReadAfterBean
readAfterBean.recordStatus = data
notifyItemChanged(position, "recordStatus")
}
这样的数据不会频繁的干扰动画同UI的刷新。
标签:动画,listOf,holder,频繁,item,payloads,recordStatus,position,RecyclerView From: https://blog.51cto.com/u_14523369/6183206