Respond to a user sliding a finger to the right quickly on the screen
1.
Import the following classes:
•
net.rim.device.api.ui.TouchEvent
•
net.rim.device.api.ui.TouchGesture
•
net.rim.device.api.ui.Field
•
net.rim.device.api.ui.Manager
•
net.rim.device.api.ui.Screen
2.
Create a class that extends the
Manager
class, the
Screen
class, the
Field
class, or one of the
Field
subclasses.
public class newButtonField extends ButtonField {
3.
In your implementation of the
touchEvent(TouchEvent message)
method, invoke
TouchEvent.getEvent()
.
4.
Check if the value that
TouchGesture.getSwipeDirection()
returns is equal to
TouchGesture.SWIPE_WEST
.
protected boolean touchEvent(TouchEvent message) {
switch(message.getEvent()) {
case TouchEvent.GESTURE:
TouchGesture gesture = message.getGesture();
switch(gesture.getEvent()) {
case TouchGesture.SWIPE:
if(gesture.getSwipeDirection() == TouchGesture.SWIPE_WEST) {
Dialog.alert("Westward swipe occurred");
return true;
}
}
return false;
}
}
Respond to a user clicking the screen
1.
Import the following classes:
•
net.rim.device.api.ui.TouchEvent
•
net.rim.device.api.ui.Field
•
net.rim.device.api.ui.Manager
•
net.rim.device.api.ui.Screen
2.
Create a class that extends the
Manager
class, the
Screen
class, the
Field
class, or one of the
Field
subclasses.
public class newButtonField extends ButtonField {
Development Guide
Touch screen events
36