如何将列表视图项目拖放到另一个列表视图
嗨,我是 Raynast,我是 Android 编程新手 现在我的项目中有一个关于Listview拖放的小问题
我决定从数据库布局到三个Listview查询
_________________________
|list_1 |list_2 |list_3 |
|_______|_______|_______|
|_______|_______|_______|
|| ||| ||| ||
||item1|||item5|||item8||
||_____|||_____|||_____||
|_______|_______|_______|
|| ||| ||| ||
||item2|||item6|||item9||
||_____|||_____|||_____||
|_______|_______| |
|| ||| || |
||item3|||item7|| |
||_____|||_____|| |
|_______| | |
|| || | |
||item4|| | |
||_____|| | |
|_______|_______|_______|
我使用android平台2.3.1
我想将item1从Listview1拖动到liewview2或liewview3 并在 listviewitem 之间放置
我尝试研究解决方案来解决这个问题,但我没有找到!
观察: MotionEvent 有action_up action_down 没有action_right,left
我想知道解决此问题的解决方案 如果不可能请告诉我或提出另一种方法来进行此活动,请
提前致谢
您的回复对我和另一个人非常有用
Hi I'm Raynast I'm a newbie for Android Programming
Now I have a little problem from my project about Listview Drag and Drop
I decide layout to Three Listview query from database
_________________________
|list_1 |list_2 |list_3 |
|_______|_______|_______|
|_______|_______|_______|
|| ||| ||| ||
||item1|||item5|||item8||
||_____|||_____|||_____||
|_______|_______|_______|
|| ||| ||| ||
||item2|||item6|||item9||
||_____|||_____|||_____||
|_______|_______| |
|| ||| || |
||item3|||item7|| |
||_____|||_____|| |
|_______| | |
|| || | |
||item4|| | |
||_____|| | |
|_______|_______|_______|
I use android platform 2.3.1
I want to Drag item1 from Listview1 to liewview2 or liewview3
and drop between listviewitem
I try to research solution to resolve this problem but I'm not found!
Observations : MotionEvent have action_up action_down don't have action_right,left
I want to know solution to resolve this problem
If it not possible tell me or propose another method to make this activity please
Thank in advance
Your response will be very useful for me and another one
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您好,我正在 github 中开发一个示例 https://github.com/mtparet/ Drag-And-Drop-Android
它可以帮助你。
欢迎所有贡献
Hello I'm developing an example of this in github https://github.com/mtparet/Drag-And-Drop-Android
It could help you.
All contribution are welcome
看一下这个在列表视图中拖放的示例。
拖放示例...单击您可以在此处找到该项目。并下载 Zip 文件..
Take a look at this sample that Drag and drop inside a List View..
Drag and drop sample...Click on You can find the project here. and Download the Zip file..
MotionEvent.getAction()
返回的ACTION_UP
和ACTION_DOWN
常量指的是手指点击的状态(例如,手指放在屏幕上) ,手指从屏幕上抬起),而不是移动方向。您还需要将MOVE
操作与ACTION_UP
和ACTION_DOWN
结合使用来完成您想要执行的操作。例如,在您的
onTouch
方法中,当您收到MOTION_DOWN
(用户按下了 ListView 项目)时,请识别用户点击了哪个项目。然后,您可以跟踪MOVE
操作以提供视觉提示,例如绘制跟随手指的浮动“幽灵”版本的项目。最后,当您收到MOTION_UP
(用户在拖动后抬起手指)时,请确定他们的手指位于哪一列,并执行您需要执行的操作将数据移至另一个列表。您可以使用每个
MotionEvent
提供的 x 和 y 坐标来确定诸如用户点击了哪个项目、他们将手指移到哪个列表等信息。The
ACTION_UP
andACTION_DOWN
constants returned byMotionEvent.getAction()
refer to the state of finger taps (for example, finger is placed down on screen, finger is lifted up from screen), not to movement direction. You will need to also use theMOVE
action in combination withACTION_UP
andACTION_DOWN
to accomplish what you're trying to do.For example, in your
onTouch
method, when you receiveMOTION_DOWN
(user has pressed down on the ListView item), identify which item the user tapped on. You can then track theMOVE
action to give visual cues, such as to draw a floating "ghost" version of the item that follows their finger. Finally, when you receiveMOTION_UP
(user lifted their finger after dragging), identify which column their finger was over and do whatever you need to do to move the data over to the other list.You can use the x and y coordinates provided with each
MotionEvent
to determine things like which item the user tapped on, which list they moved their finger over, etc.希望 http://techdroid.kbeanie.com/2011/10/ Drag-and-drop-honeycombics.html 这将在一定程度上解决你的问题,但仍然没有得到完美的解决方案......
hope http://techdroid.kbeanie.com/2011/10/drag-and-drop-honeycombics.html this will solve your problem up to some extend but still not got the perfect solution....