khaleel_jageer khaleel_jageer - 20 days ago 10
Android Question

How to update single item in recyclerview?

I'm trying to update the recyclerview item using following code snippet.

public void setItemToPostion(WatchListEpisodeBean watchListBean, int itemPosition) {
this.watchListBean.add(itemPosition, watchListBean);
notifyItemChanged(itemPosition);
}


It works fine. That's item at position updated with new data. But the problem is item cloned to its next position(appears in next position). I don't find what's wrong with my code.

This is appcompat & support design lib versions:

compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'


Please help me to fix this. Thanks in advance.

Answer

Your item is clone because you are adding item.

Try to use set instead of add like this

public void setItemToPostion(WatchListEpisodeBean watchListBean, int itemPosition) {
    this.watchListBean.set(itemPosition, watchListBean);
    notifyItemChanged(itemPosition);
}