public void replaceItem ( @ NonNull final T oldObject , @ NonNull final T newObject ) { synchronized ( mLock ) { final int position = getPosition ( oldObject ) ; if ( position == - 1 ) { // not found, don't replace return ; } mObjects . remove ( position ) ; mObjects . add ( position , newObject ) ; if ( isItemTheSame ( oldObject , newObject ) ) { if ( isContentTheSame ( oldObject , newObject ) ) { // visible content hasn't changed, don't notify return ; } // item with same stable id has changed notifyItemChanged ( position , newObject ) ; } else { // item replaced with another one with a different id notifyItemRemoved ( position ) ; notifyItemInserted ( position ) ; } } }
replaces the old with the new item . The new item will not be added when the old one is not found .