Linked Questions

Popular Questions

Update RecyclerView images count in UI TextView after Drag and drop

Asked by At

In my app images are displayed inside cardview in recyclerview. There are two elements one is imageview and other is Textview which displays the image position i.e. card position in recyclerview.

I have implemented onRowMoved() for Drag and Drop Here is the code:

public void onRowMoved(int fromPosition, int toPosition) {
    if (fromPosition < toPosition) {
        for (int i = fromPosition; i < toPosition; i++) {
            Collections.swap(images, i, i + 1);
    } else {
        for (int i = fromPosition; i > toPosition; i--) {
            Collections.swap(images, i, i - 1);
    notifyItemMoved(fromPosition, toPosition);

But I have to update the count of cards when drag and drop is happening I try to call notifyItemRangeChanged() at last in onRowMoved() but from this method Drag and drop is not perform in a smooth way means when I will drag the card and moved it, it drops automatically and cards count is updated by notifyItemRangeChanged().

It will not allow to scroll the card after drag and drop it to the last location.

This problem is not occurring, if I will not use the notifyItemRangeChanged() method in onRowMoved().

This is my activity output screen enter image description here

So anyone please tell me how to update cards count position.

Related Questions