I have a RecyclerView
and I want to show that RecyclerView
with two sections. First time section one will be empty and I want to drag item from section two to section one. When item is added to section one and it should be deleted from section two and vice versa.

- 108
- 1
- 9
-
@Abdul , Hey Please help me if you have any idea about that. – Vishal Jul 22 '16 at 02:41
-
I solve your problem see my answer.. – bhumika rijiya Jul 23 '16 at 06:14
3 Answers
Try this,it worked with me in my app,
In your adapter class put this below code,
here MessageList is name of the Arraylist,
public void swap(int firstPosition, int secondPosition)
{
Collections.swap(MessageList, firstPosition, secondPosition);
notifyItemMoved(firstPosition, secondPosition);
}
now add this small class separately,
here
Adapter
is name of the Adapter class put your adapter name
public class MovieTouchHelper extends ItemTouchHelper.SimpleCallback {
Aadapter recycleAdapter;
public MovieTouchHelper(Aadapter recycleAdapter) {
super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
this.recycleAdapter = recycleAdapter;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
recycleAdapter.swap(viewHolder.getAdapterPosition(), target.getAdapterPosition());
return true;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
recycleAdapter.remove(viewHolder.getAdapterPosition());
}
}
Then in your mainActivity where you defined recycleview,
ItemTouchHelper.Callback callback = new MovieTouchHelper(adapter);
ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(rv_list);
here
rv_list
is name of recycleview.
Follow this steps and if you find any problem or you can't swip items then directly tell me...
See this GIF

- 440
- 1
- 5
- 42
-
@Vishal you can also use this solution as you have the same problem regarding this .....:-):-) – bhumika rijiya Jul 23 '16 at 04:12
-
-
i want to added in two group first one is added and second one is invite just like my above picture – Vishal Jul 26 '16 at 04:57
-
-
i want click not touch just click on add button data move to top .BTW move not working properly sometime . – Vishal Jul 29 '16 at 06:46
-
Hi @bhumikarijiya i have done with drag n drop.but now i want to steak first sequence value. in above gif while you move 4th to 3rd then item should move but first textbox value should not reset, it should be as it is. any idea? – RaRa Sep 07 '19 at 19:59
You can use the following links:
https://github.com/cymcsg/UltimateRecyclerView
https://github.com/wasabeef/recyclerview-animators
use any one of this. I hope it will help you.
Import the lib in your project.

- 108
- 1
- 12
You should use the ItemTouchHelper
from the RecyclerView.ItemDecoration
class.
I just accomplish the behavior you're willing by following this tutorial:
https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-b9456d2b1aaf#.p6vykzstq

- 271
- 3
- 6