BlackBerry - TouchEvent on multiple managers
Posted
by rupesh
on Stack Overflow
See other posts from Stack Overflow
or by rupesh
Published on 2010-04-09T12:52:08Z
Indexed on
2010/04/12
5:43 UTC
Read the original article
Hit count: 661
blackberry
|blackberry-storm
Hi all
i am new to blackberry application development here is my question i am using two verticalfieldmanager "layout" and "manager" in my application. layout has three custom button field and layout is inside manager.
i am not able to implement touch event , here is my code:
public class MenuScreen extends MainScreen {
public MenuScreen() {
super(Screen.DEFAULT_CLOSE);
Bitmap menuBackgroundImage = Bitmap
.getBitmapResource("com/greetings/Images/MenuBackground.jpg");
final VerticalFieldManager layout = new VerticalFieldManager() {
public boolean touchEvent(TouchEvent message) {
int x = message.getGlobalX(1);
int y = message.getGlobalY(1);
if (getExtent().contains(x, y)) {
int fieldI = getFieldAtLocation(x, y);
Field field = getField(fieldI);
field.setFocus();
return super.touchEvent(message);
}
return false;
}
};
ButtonField categories = new ButtonField("Categories") {
public void run() {
Dialog.alert("one");
}
public boolean touchEvent(TouchEvent message) {
int x = message.getX(1);
int y = message.getY(1);
int w = getWidth();
int h = getHeight();
if (x >= 0 && x <= w && y >= 0 && y <= h) {
switch (message.getEvent()) {
case TouchEvent.DOWN:
setFocus();
return true;
case TouchEvent.UNCLICK:
run();
return true;
}
}
return false;
}
};
ButtonField help = new ButtonField("Help") {
public void run() {
Dialog.alert("help");
}
public boolean touchEvent(TouchEvent message) {
int x = message.getX(1);
int y = message.getY(1);
int w = getWidth();
int h = getHeight();
if (x >= 0 && x <= w && y >= 0 && y <= h) {
switch (message.getEvent()) {
case TouchEvent.DOWN:
setFocus();
return true;
case TouchEvent.UNCLICK:
run();
return true;
}
}
return false;
}
};
ButtonField developer = new ButtonField("Developer") {
public void run() {
Dialog.alert("Developer");
}
public boolean touchEvent(TouchEvent message) {
int x = message.getX(1);
int y = message.getY(1);
int w = getWidth();
int h = getHeight();
if (x >= 0 && x <= w && y >= 0 && y <= h) {
switch (message.getEvent()) {
case TouchEvent.DOWN:
setFocus();
return true;
case TouchEvent.UNCLICK:
run();
return true;
}
}
return false;
}
};
layout.add(categories);
layout.add(help);
layout.add(developer);
VerticalFieldManager manager = new VerticalFieldManager() {
protected void sublayout(int width, int height) {
width = Display.getWidth();
height = Display.getHeight();
super.sublayout(width, height);
setPositionChild(layout, width - 245, height - 350);
setExtent(width, height);
}
};
manager.setBackground(BackgroundFactory
.createBitmapBackground(menuBackgroundImage));
manager.add(layout);
add(manager);
}
}
© Stack Overflow or respective owner