You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need to check that itemViewType is the same for the entire data set during onItemRangeInserted/Removed. Since itemViewType can be dependent on position, it is possible for views outside of the notified range to change. Calling notifyDataSetChanged() instead would result in the correct behavior (at the cost of rebinding every view), but if you want to keep the behavior consistent with RecyclerView, you should validate items outside of the range and rebind items whose itemViewType has changed.
val items = (0..10).toMutableList()
val adapter = object : RecyclerView.Adapter<MyViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
MyViewHolder(TextView(parent.context))
override fun getItemCount() = items.size
override fun getItemViewType(position: Int) = position % 2
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
(holder.itemView as TextView).text = items[position].toString()
holder.itemView.setBackgroundColor(
if (getItemViewType(position) == 0) Color.GREEN else Color.RED)
}
}
list.adapter = adapter
button.setOnClickListener {
items.removeAt(4)
adapter.notifyItemRangeRemoved(4, 1)
}
The text was updated successfully, but these errors were encountered:
Need to check that itemViewType is the same for the entire data set during onItemRangeInserted/Removed. Since itemViewType can be dependent on position, it is possible for views outside of the notified range to change. Calling notifyDataSetChanged() instead would result in the correct behavior (at the cost of rebinding every view), but if you want to keep the behavior consistent with RecyclerView, you should validate items outside of the range and rebind items whose itemViewType has changed.
The text was updated successfully, but these errors were encountered: