Java – How to implement drag and drop between lists in android?

How to implement drag and drop between lists in android?… here is a solution to the problem.

How to implement drag and drop between lists in android?

I’m trying to do this so that users can drag a TextView from one ListView and drop it into another ListView, but I find this very difficult.
The biggest problem I’ve found so far is that onTouchEvents seems to only be heard in the View where the ACTION_DOWN event originated. I’ll click on a list and hear ACTION_DOWN in it. Then I’ll drag out of the list and let go of another list. But no matter where I’m going, onTouchEvent will only be called by the original list. I think it would be as simple as listening for ACTION_UP events in a receive list; But this is called in the original list, even if I am outside of it.

I’ve been a bit of a mess with my content so far. When onLongTouchEvent is called, the list tells the main activity to start draggableTextView (which has a moveTo method). Since the move event continues to be invoked on the original list, I let it keep setting the location of this draggableTextView. But I can’t insert it into another list because I can’t figure out what I’m giving up.

Solution

Yes, you are right, it is not an easy task. However, this is possible: you can check Commonsguy’s cwac-touchlist example.

Related Problems and Solutions