问题描述
我与黑莓触摸事件工作,我需要处理 TouchEvent.MOVE
, TouchEvent.UP
和 TouchEvent.DOWN
移动图像的旋转木马和 TouchEvent.CLICK
来生成一些特定的操作。
I'm working with the Blackberry Touch Event and I need to process the TouchEvent.MOVE
, TouchEvent.UP
and TouchEvent.DOWN
to move a carousel of images and the TouchEvent.CLICK
to generate some specific action.
我的问题是,的TouchEvent()
方法被调用多次。我怎样才能prevent呢?因为行为是让所有搞砸。
My problem is that the touchEvent()
method is being called several times. How can I prevent this? Because the behaviour is getting all messed up.
例如:当我只是想捕捉 TouchEvent.CLICK
事件,上下-MOVE-CLICK正在触发一个接着一个。
For example: when I just want to capture the TouchEvent.CLICK
event, the UP-DOWN-MOVE-CLICK are being triggered one after the next.
我的code执行以下操作:
My code does the following:
protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
//CHANGE THE CONTENT OF A FIELD
return true;
} else if ((message.getEvent() == TouchEvent.MOVE)
|| (message.getEvent() == TouchEvent.UP)
|| (message.getEvent() == TouchEvent.DOWN)) {
//DELETE THE FIELD
//MOVE A CAROUSEL OF IMAGES
} else {
return false;
}
}
public void moverTouch(int dx) {
//ADD THE FIELD PREVIOUSLY DELETED
}
正如你所看到的,当被捕获的点击
事件,我需要更改字段的内容,但是当移动
或 UP
或下
事件被抓获,我需要删除现场
从他的经理,做一些与图像的旋转木马的工作,然后重新添加字段previously删除。
As you can see, when the CLICK
event is captured, I need to change the content of a field, but when the MOVE
or UP
or DOWN
event is captured, I need to delete that Field
from his manager, do some working with a carousel of images, and then re-add the field previously deleted.
在传送带运动部件工作正常,但是当我试图捕捉只是点击
事件,和其他人被触发为好,但 moverTouch(
)函数不会被触发,因为有上的图像旋转木马没有实际动作,我结束了已删除的领域,我需要更新的内容。
The carousel moving part works fine, but when I try to capture JUST the CLICK
event, and the others are being triggered as well, but the moverTouch(
) function doesn't get triggered because there is no actual movement on the carousel of images, I end up with a deleted field that I need to update its content.
推荐答案
概览:
我想你需要区分触摸手势(我相信你听的东西就像一个滑动手势滚动图库图片)从正常触摸事件(特别是你需要处理的TouchEvent 。点击
申请一些具体的行动的点击图片)。
I think you need to differentiate touch gestures (I believe you are "listening" for something like a swipe gesture to scroll the gallery image) from "normal" touch events (specifically you need to process TouchEvent.CLICK
to apply "some specific action" to the clicked image).
要决定是否的TouchEvent
重新presents手势有一个 TouchEvent.GESTURE
不变。然后就可以知道究竟 TouchGesture
通过调用重新presents TouchEvent.getGesture()
。
To decide whether the TouchEvent
represents a gesture there is a TouchEvent.GESTURE
constant. Then it is possible to know what exactly TouchGesture
it represents by calling TouchEvent.getGesture()
.
一些示例code触摸手势可以被看作这里。
Some sample code for touch gestures can be viewed here.
这篇关于触摸事件黑莓多次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!