RecyclerView corrupts view using notifyItemMoved()

前端 未结 4 2062
不知归路
不知归路 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:26

    To get the actual position of your item after a drag&drop, add this method to your adapter:

    private int getItemPosition(Item item){ // (<-- replace with your item)
        int i = 0;
        // (replace with your items and methods here)
        for (Item currentItem : mItems) {
            if (currentItem.getItemId() == item.getItemId()) break;
            i++;
        }
        return i;
    }
    

    and call this instead of the position given by the viewHolder.

提交回复
热议问题