RecyclerView corrupts view using notifyItemMoved()

前端 未结 4 2064
不知归路
不知归路 2021-01-02 04:08

I\'m having a problem with using the notifyItemMoved() method. It seems to be incorrectly displaying unmoved views.

My list has 4 element in it. What I w

4条回答
  •  离开以前
    2021-01-02 04:43

    Well, I handled it in a slightly different way, might help others.

            Collections.swap(mItemList, fromPosition, toPosition);
            // Need to do below, because NotifyItemMove only handle one sided move
            Item fromItem = mItemList.get(fromPosition);
            Item toItem = mItemList.get(toPosition);
            notifyItemChanged(fromPosition, toItem);
            notifyItemChanged(toPosition, fromItem);
    

    I had to reorder items on a grid, and save the positions to a file. @Graeme was right, but i didn't wanted to give up on swapping. So just like @saganaut i sticked to notifyItemChanged. But only using notifyItemChanged sometimes left both swapped items on my grid with same items, so I binded the items with notifyItemChanged. It is not killing the animation, and is working as expected.

提交回复
热议问题