滑动时获取列表视图的行位置
我知道在此处之前提出过此类问题。 我已经尝试过两种手势检测器:
wholelistview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
});
仅检测滑动(此处无法获取行位置)。
在 getview 中类似:
public View getView(int position, View convertView, ViewGroup parent) {
//other stuff
convertview.setOnTouchListener(same as above);
}
但无法检测滑动。
对此有任何解决方案吗??? 我只想要进行滑动的行位置。
I know this type of question is asked before here.
I have tried both gesture detector :
wholelistview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
});
which detects only swipe(cannot get row position here).
similarly in getview:
public View getView(int position, View convertView, ViewGroup parent) {
//other stuff
convertview.setOnTouchListener(same as above);
}
but cannot detect swipe.
Any solution for this ???
I want only the row position on which swipe is made.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
hanry 你会遇到什么样的错误?我已经实现了它并且运行良好。但我不是存储元素的位置,而是存储视图持有者,其中其他元素也具有模型属性。请记住,您必须检查 ConvertView 是否不为空。看一下代码:
然后
希望有所帮助。
ps:如果您对视图持有者和标签一无所知,我建议您查看那里。弗兰肯斯坦给出的链接中描述了我的方法。
hanry what kind of errors do you get? I've implemented it and it works perectly. But instead of storing the position of the element I'm storing the view holder that among the others also have the model property. Remember that you have to check if the convertview isn't null. Take a look at the code:
and then
hop that helps.
ps: If you don't know anything about view holders and tags I suugest to see there. And my approach has been described in the link that Frankenstein gave.
要获取视图的行位置,请通过此函数获取列表视图的 onTouch 传递的视图位置
。它返回子级的索引。
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.5_r1/android/view/ViewGroup.java#ViewGroup.indexOfChild% 28android.view.View%29
To get row position for your view, get position of view passed by onTouch for your listview by this function
It returns index of child.
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.5_r1/android/view/ViewGroup.java#ViewGroup.indexOfChild%28android.view.View%29
您可以执行 getTag 和 setTag 来了解视图的标签,并使用它来确定已刷过哪一行
,以及 从链接中滑动
我没有实现这个..所以你必须测试错误..但根据我的说法,这可能是实现这一目标的好方法你想要什么 做。
you can do getTag and setTag to know the tag of the view and using that you can decide which row has been swiped
and for swipe from the link
I didn't Implemented this..so you will have to test for error..but According to me this can be a good way to achieve what you want to do.
像这样?
like this?