4

I'm trying to make it so that the user can drag a textview from one listview and then drop it into another, and I'm finding it to be very difficult.
The biggest problem I have found so far is that onTouchEvents seem to only be heard in the view that the ACTION_DOWN event originated in. I'll click in one list and the ACTION_DOWN is heard in there. Then I'll drag outside the list and let go over another list. But the onTouchEvent is only being called for the original list, no matter where I'm going. I thought it was going to be as simple as listening for an ACTION_UP event in the receiving list; but that's called on the original list even though I'm outside it.

What I have so far is a bit messy. When onLongTouchEvent is called, the list tells the main activity to start dragging a draggableTextView (which has a moveTo method). Since the move events continue to be called on the original list, I have it continually setting the position of this draggableTextView. But I can't insert it into another list because I can't figure out what I'm letting go on top of.

phailhaus
  • 51
  • 2
  • Why do you have 2 listviews in the same activity/view? – Falmarri Dec 30 '10 at 22:02
  • It might be helpful to have a look at how the AOSP Launcher app works with drag and drop across different views. The source is here: http://android.git.kernel.org/?p=platform/packages/apps/Launcher2.git;a=tree;f=src/com/android/launcher2;h=c7c52ec9047f7d4dff5388c3cad4fec12414bd57;hb=HEAD – adamp Dec 31 '10 at 01:43
  • This wouldn't be for a phone, but for an android pad. I don't have the emulator for the pad, so I'm improvising by using two lists in one activity on the phone. – phailhaus Dec 31 '10 at 16:12

1 Answers1

0

Yes, you are right, this is not an easy task. However it is possible: you might check commonsguy's cwac-touchlist example.

Antonio
  • 11,413
  • 6
  • 34
  • 48
StanislavK
  • 1,962
  • 15
  • 16
  • 2
    As an FYI, `TouchListView` won't work between lists. That is simply for ordering items within a list. The code for it is culled from the Music app in the AOSP, and, frankly, I don't understand most of it. Drag-and-drop within a list was a popular enough request that I took the time to rip out that code and make it somewhat reusable. I have no idea if it is a good example of how to do drag-and-drop, though. – CommonsWare Dec 30 '10 at 21:50
  • @CommonsWare, you are right - my misunderstanding. It will be easier to stay and do the drag and drop within one list (in the activity/view) only. – StanislavK Dec 30 '10 at 23:13