BlackBerry Clicking Outside the Field

I am implementing a custom ImageButton for touch control devices (9500,9550,9800, ...) I have a problem that clicking (touching) an external field generates an event in the focused field. (When expanding Field , BitmapField )

I can solve this by moving the focus to an empty field, but it is not very nice. The strange thing is that this behavior is for Field , BitmapField , but not for ButtonField . Apparently, when focusing the ButtonField external clicks do not generate a button event.

I tried to extend ButtonField , but I could not get rid of this stupid Button background.

So my question is; What is the difference in behavior between Field and ButtonField that causes events to be generated outside of Field ?

this is how i removed the background button:

  // cahange button border setBorder(BorderFactory .createSimpleBorder(new XYEdges(0, 0, 0, 0))); setBorder(VISUAL_STATE_ACTIVE, BorderFactory .createSimpleBorder(new XYEdges(0, 0, 0, 0))); 
+1
source share
1 answer

You just need to add the check to your touchEvent () for ImageButton

 protected boolean touchEvent(TouchEvent message) { //make sure the touch is withing the bounds of our Field if(message.getX(1) < 0 || message.getX(1) > getWidth() || message.getY(1) < 0 || message.getY(1) > getHeight()) { return false; } //Do your work } 

A touch event is sent to the focused field, even if it is not actually in the field, you must return false so that the contained dispatcher knows to send it to the next field that will receive it (the field in which the touch is on or nothing if it is in empty space).

Edit: To remove the button background, override protected void applyTheme() {}

0
source

All Articles