检测搜索栏拇指的长按事件 [英] Detect long click event for seekbar thumb

查看:29
本文介绍了检测搜索栏拇指的长按事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Android 应用中有一个搜索栏.我需要检测搜索栏的长按事件才能执行某些操作.建议我任何解决方案.我已经在搜索栏上尝试过 onLongClickListener,但它不起作用.

I have a seekbar in my android app. I need to detect the long click event for the seekbar in order to perform some action. Suggest me any solution. I have tried out onLongClickListener on the seekbar, but it is not working.

推荐答案

在阅读文档和其他 SeekBar LongClick 开发人员的问题后,它看起来像 LongClickListener 不适用于 SeekBar.

After reading the documentation and other SeekBar LongClick problems with developers it looks like the LongClickListener is not working with SeekBar.

但是,我可以建议一个解决方法:

However, I can suggest a workaround :

  1. SeekBar :您可以为搜索栏实现 onTouch 事件,对于 MotionEvent.ACTION_DOWN 操作,您可以设置超时 1 秒并将其视为 长按.如果 MotionEvent.ACTION_UP 被调用,则取消计时器.

  1. SeekBar : You can implement onTouch event for seekbar and for MotionEvent.ACTION_DOWN action you can set a timeout for 1 second and consider it the LongClick. Cancel the timer if MotionEvent.ACTION_UP is called.

Thumb :您可以实现 OnSeekBarChangeListener 并且在 onStartTrackingTouch 事件上,您可以将超时设置为 1 秒并将其视为 LongClick如果在超时期间没有调用 onStopTrackingTouchonProgressChanged(如果 onStopTrackingTouch/onProgressChanged 被调用,则取消计时器.)

Thumb : You can implement OnSeekBarChangeListener and on onStartTrackingTouch event you can set a timeout for 1 second and consider it the LongClick if onStopTrackingTouch or onProgressChanged is not called during the timeout (Cancel the timer if onStopTrackingTouch/onProgressChanged is called.)

不发布代码,因为我的 IDE 现在没有打开.但我希望你能找到使用这个逻辑的方法.(如果您不了解我提到的事件,请阅读文档)

Not posting the code because my IDE isn't open now. But I hope you can find out the way using this logic. (Read documentations if you don't know about the events I mentioned)

谢谢.

这篇关于检测搜索栏拇指的长按事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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