I used recyclerView with notifyItemRangeInserted and notifyItemRangeRemoved.
RecyclerView in my screen used width="match_parent" and height="wrap_content"
I need to show or hide ALL elements in my recylerView. I used this code and it works nice. Element hide and show after change visibility
flag.
But for some reason animation for insertion is present and for deletion there is no. Why?
class MyAdapter : RecyclerView.Adapter<ViewHolder>() {
var objects: List<MyData> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
var visibility: Boolean = true
set(value) {
field = value
when (field) {
true -> notifyItemRangeInserted(0, cards.size)
false -> notifyItemRangeRemoved(0, cards.size)
}
}
override fun getItemCount(): Int = if (visibility) objects.size else 0