如何在android中的列表之间实现拖放?

时间:2022-02-04 14:27:42

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.

我正在尝试这样做,以便用户可以从一个列表视图拖动文本视图,然后将其放到另一个列表视图中,我发现它非常困难。到目前为止我发现的最大问题是onTouchEvents似乎只能在ACTION_DOWN事件发生的视图中听到。我将在一个列表中单击并在那里听到ACTION_DOWN。然后我会拖到列表之外然后放开另一个列表。但无论我走到哪里,onTouchEvent只会被调用原始列表。我认为这就像在接收列表中侦听ACTION_UP事件一样简单;但即使我在外面,也会在原始列表中调用它。

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.

到目前为止,我有点凌乱。当调用onLongTouchEvent时,列表会告诉主活动开始拖动draggableTextView(具有moveTo方法)。由于移动事件继续在原始列表中调用,因此我不断设置此draggableTextView的位置。但我无法将其插入另一个列表,因为我无法弄清楚我放在哪里。

1 个解决方案

#1


0  

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

是的,你是对的,这不是一件容易的事。但是有可能:您可以查看commonsguy的cwac-touchlist示例。

#1


0  

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

是的,你是对的,这不是一件容易的事。但是有可能:您可以查看commonsguy的cwac-touchlist示例。