不能同时处理这两个点击和触摸事件 [英] Can't handle both click and touch events simultaneously

查看:122
本文介绍了不能同时处理这两个点击和触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想处理触摸事件,点击一个按钮的事件。我做到以下几点:

I am trying to handle touch events and click events on a button. I do the following:

button.setOnClickListener(clickListener);
button.setOnTouchListener(touchListener);

在任何一个监听器被注册的事情正常工作,但是当我尝试使用它们都只有触摸事件被触发。任何解决方法吗?我究竟做错了什么?

When any one listener is registered things work fine but when I try to use them both only the touch events are fired. Any workaround? What am I doing wrong?

推荐答案

之间有一个微妙的,但很重要的区别 ClickListener TouchListener 。该 TouchListener 执行前视​​图能够对事件做出响应。该 ClickListener 将接收其事件后,才认为已经处理了。

There is a subtle, yet very important difference between the ClickListener and the TouchListener. The TouchListener is executed before the view can respond to the event. The ClickListener will receive its event only after the view has handled it.

所以,当你触摸屏幕时, TouchListener 首先执行,当您返回为您的活动,在 ClickListener 将永远不会得到它。但是,如果你preSS设备的轨迹球,在 ClickListener 应该被解雇,因为 TouchListener 不会回应吧。

So when you touch your screen, the TouchListener is executed first and when you return true for your event, the ClickListener will never get it. But if you press the trackball of your device, the ClickListener should be fired because the TouchListener will not respond to it.

这篇关于不能同时处理这两个点击和触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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