Speed up Your Android RecyclerView Using DiffUtil | raywenderlich.com

Hello archeremiya,

I believe you’re describing this scenario, right:

override fun onBindViewHolder(holder: ItemViewHolder, pos: Int) {
  onBindViewHolder(holder, pos, emptyList())
}

onBindViewHolder is called when the first data is added to the list. Since there are no other data to compare your data, the payload is going to be empty.

override fun onBindViewHolder(viewHolder: ItemViewHolder, pos: Int, payload: List<Any>) 

Since it’s necessary to override both onBindViewHolder’s, to avoid duplicating the code, I’m calling the onBindViewHolder with an empty list. All the logic is handled in this second function.

This sample already handles the onClickEvent. If you need to migrate it to the adapter, you need to add its logic when an item is set, otherwise, you might get the listener from a different element in the list.

1 Like