GridView中获取项触摸 [英] GridView Get Item On Touch

查看:116
本文介绍了GridView中获取项触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得该项目选择时,我摸一个gridview,我不能使用的onClick作为启动另一个活动。什么我想要实现的是能够在GridView中移动项目,并因为我无法找到这样做我想要做的方式的一种方式。

I'm trying to get the item selected when i touch a gridview, i cant use the onClick as that starts another activity. What I'm trying to achieve is to be able to move items in a gridview around and since i cant find a way of doing it I'm trying to make a way..

所以呀..有没有办法让该项目已被感动,我使用的是矩形已经尝试过,也没有适当的工作。

So yeah.. Is there a way to get which item has been 'touched', I've tried using a Rect and it hasn't worked properly..

(我可以只详细..我不能使用onItemClick这个..)

(Can i just elaborate.. i Cant use the onItemClick for this..)

任何帮助将是巨大的,谢谢! :)

Any help would be great, Thank you! :)

推荐答案

如果使用onLongClickListener的格兰登Trullinger的建议是不够​​的你,试试<一href="http://developer.android.com/reference/android/widget/AbsListView.html#pointToPosition%28int,%20int%29">GridView#pointToPosition(int x,int y)对,你可以从一个叫 View.OnTouchListener ,使用 MotionEvent SX和y坐标。随着那个位置,你可以在该位置使用子视图<一href="http://stackoverflow.com/questions/257514/android-access-child-views-from-a-listview/2679284#2679284">this回答,和/或可使用获取适配器项目本身<一href="http://developer.android.com/reference/android/widget/AdapterView.html#getItemAtPosition%28int%29">AdapterView#getItemAtPosition(int)

If Glendon Trullinger's suggestion of using onLongClickListener isn't sufficient for you, try GridView#pointToPosition(int x, int y), which you can call from a View.OnTouchListener, using the MotionEvent's x and y coordinates. With that position, you can get the child view at that position using this answer, and/or you can get the adapter item itself using AdapterView#getItemAtPosition(int)

这篇关于GridView中获取项触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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