Android:如何防止拖动被解释为长按
当我插入代码来显示上下文菜单时,它工作得很好,只是菜单不仅在固定长按后出现,而且在拖动结束时(不需要)出现。
我已经能够通过以下方法来防止这种情况:向视图添加 ScrollInProgress 标志,通过在 onCreateContextMenu(...) 方法的开头检查此标志,以及是否通过绕过将项目添加到的代码来设置该标志上下文菜单。
但是,我想知道是否有一种更简单的方法来防止拖动屏幕时创建上下文菜单。
When I inserted code to display a context menu it worked fine except that the menu appeared not only after a stationary long press but also (unwanted) at the end of a drag.
I have been able to prevent this by: adding a ScrollInProgress flag to the View, by checking this flag at the beginning of the onCreateContextMenu(...) method, and if the flag is set by by-passing the code which adds items to the context menu.
However, I wonder if there is a simpler way of preventing the creation of a context menu when the screen is dragged.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
澄清一下,手势检测器不是在接收长按吗?
如果是,可以使用 setIsLongpressEnabled(boolean isLongpressEnabled) 禁用此功能
To clarify, it isn't the gesture detector that's picking up the long press?
If it is, this can be disabled using setIsLongpressEnabled(boolean isLongpressEnabled)