How to update/refresh specific item in RecyclerView

前端 未结 13 1365
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 18:31

I\'m trying to refresh specific item in RecyclerView.

Story: Whenever user clicks on item, it shows AlertDialog. User can

13条回答
  •  误落风尘
    2020-11-29 18:57

    I think I have an Idea on how to deal with this. Updating is the same as deleting and replacing at the exact position. So I first remove the item from that position using the code below:

    public void removeItem(int position){
        mData.remove(position);
        notifyItemRemoved(position);
        notifyItemRangeChanged(position, mData.size());
    }
    

    and then I would add the item at that particular position as shown below:

    public void addItem(int position, Landscape landscape){
        mData.add(position, landscape);
        notifyItemInserted(position);
        notifyItemRangeChanged(position, mData.size());
    }
    

    I'm trying to implement this now. I would give you a feedback when I'm through!

提交回复
热议问题