问题
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.
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.
For example: when I just want to capture the TouchEvent.CLICK
event, the UP-DOWN-MOVE-CLICK are being triggered one after the next.
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
}
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.
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.
回答1:
At a glance:
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).
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()
.
Some sample code for touch gestures can be viewed here.
来源:https://stackoverflow.com/questions/16818850/touch-event-blackberry-triggered-multiple-times