如何在android中实现列表之间的拖放操作? [英] How to implement drag-and-drop between lists in android?

查看:121
本文介绍了如何在android中实现列表之间的拖放操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让它使用户可以从一个列表视图拖动一个文本视图,然后将其放在另一个列表中,我发现它非常困难。

最大的问题我到目前为止发现,onTouchEvents似乎只有在ACTION_DOWN事件发生的时候才会被听到。我会点击一个列表,并在那里听到ACTION_DOWN。然后我会拖出列表外面放过另一个列表。但是,onTouchEvent只是被原来的列表所调用,无论我要去哪里。我以为在接收列表中收听一个ACTION_UP事件将会很简单;但即使我在外面也是原来的名单。

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.

我到目前为止有点乱七八糟。当onLongTouchEvent被调用时,该列表告诉主要的活动是开始拖动一个draggableTextView(它有一个moveTo方法)。由于移动事件继续在原始列表中被调用,所以我不断地设置这个draggableTextView的位置。但是我无法将其插入到另一个列表中,因为我无法弄清楚我正在放弃的是什么。

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.

推荐答案

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

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

这篇关于如何在android中实现列表之间的拖放操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆