Transferring items between RecyclerView in Kotlin

21 Views Asked by At

I'm building an Android application and I'm trying to make items move between lists at the click of a button (removed from list A and moved to list B) It doesn't work for me, sometimes the items are just removed and don't appear in the new list, sometimes they're not removed either.

I tried to do a simple data transmission to the adapter to remove the item and create an item in the dash list. In practice, nothing happens.

1

There are 1 best solutions below

0
Fahad Bin Asif On

To remove item from list and updating in RecyclerView

listOne.remove(5);
adapterOne.notifyItemRemoved(5);                 

To Add item in list a specific position in RecyclerView

listTwo.add(5, yourData);
adapterTwo.notifyItemInserted(5);

Or simply you can call notifyDataSetChanged() on adapters after data changed in any of the lists respectively.