Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable RecyclerView itemAnimator for specific items

in recyclerView itemAnimator android, it is possible to disable/enable auto itemAnimation animation for specific adapter position, in real time?

like image 879
Ido Kahana Avatar asked Jul 24 '16 10:07

Ido Kahana


1 Answers

Try following code snippet:

val ignoreList = listOf<Int>(5, 6, 7)
recyclerView.itemAnimator = object : DefaultItemAnimator(){

    override fun canReuseUpdatedViewHolder(viewHolder: RecyclerView.ViewHolder): Boolean {
        if(ignoreList.contains(viewHolder.adapterPosition))
            return true;
        else
            return super.canReuseUpdatedViewHolder(viewHolder)
    }
}

You should modify ignoreList based on your needs.

like image 142
Mir Milad Hosseiny Avatar answered Oct 18 '22 23:10

Mir Milad Hosseiny