gpt4 book ai didi

android - ListView 每一行的滑动检测

转载 作者:IT老高 更新时间:2023-10-28 23:07:06 34 4
gpt4 key购买 nike

我有一个位于 SD 卡中的视频列表。此时,我只需要帮助为 ListView 中的每一行创建手势或滑动检测。感谢stackoverflow上的这个问题Fling gesture detection on grid layout ,我在 ListView 上实现了手势。它现在可以轻松检测用户何时向右或向左滑动。但是这个手势是针对整个 ListView 的。我只想知道如何为各个行实现这种滑动检测。例如,应用程序现在制作一个打印“Right Swipe”、“Left Swipe”的 toast。我只想让它像“在第 1 行向右滑动”、“在第 3 行向左滑动”等。我希望我的问题很清楚。

期待一些有用的回复。谢谢

最佳答案

查看 this answer并使用 pointToPosition onFling 事件中的方法

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
Toast.makeText( listAdapter.getItem( listView.pointToPosition(Math.round(e1.getX()), Math.round(e1.getY())).toString());
return super.onFling();
} catch( Exception e ) {
// do nothing
}
}

关于android - ListView 每一行的滑动检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6597883/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com