7

I need to know how I can implement Drag & Drop in Android for the Gingerbread version. As I know Gingerbread doesn't support that by default.

What I have coded: a ViewGroup class to hold dynamic added child, each child should after a long click be able to get moved through a finger tap/move. To solve this, i have a OnLongClickListener attached to each View's child and my ViewGroup have implemented both the methods onTouch() to get the down/up/move events and the method onLongClick() to response to the long click on each child.

Now my problem is as follows: I long tap a child, I can move it and can end the action through the ACTION_UP event. But, I can't long tap this child again - is there a way or library that can handle that?

I think, I don't need a really D&D library/function because I only will order some icons in this ViewGroup - each child gets added to the ViewGroup via code, so I don't have a really DropTarget I think.

AndroidLearner
  • 4,500
  • 4
  • 31
  • 62
Andreas
  • 1,617
  • 15
  • 18
  • i fixed the problem as follows: 1.) let each child have a new instance of OnLongClickListener, this prevents the parent to response to the LongClick event. 2.) return the correct values (true/false) in onTouch() event – Andreas Jan 11 '12 at 08:17

2 Answers2

0

This example may help you. This example has a complete drag and drop framework for pre 3.0. And also the feature you are requesting with "dragging a dropped child" as default.

Magakahn
  • 498
  • 9
  • 31
0

Look at the project at https://github.com/thquinn/DraggableGridView. This code really helped me out.

Follow the onLayout() and the onTouch() in the DraggableGridView class. Let me know if this was/wasn't helpful. It's very similar to your situation in regards to ViewGroup and adding views.

andr
  • 15,970
  • 10
  • 45
  • 59
WilliaGuy
  • 111
  • 2
  • 7