Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
milanvishal
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Re: Issue in Button Field Listener

See this .

I think this will remain in proper format so it may be usefull to you.

 

Regards,

 

public class TwoBitmapCustomField extends BitmapField {

private Bitmap bitmapOnFocus;
private Bitmap bitmapOffFocus;

int width = 0;
int height = 0;

public TwoBitmapCustomField(String actionCommand, String strOffFocus,
String strOnFocus, long style) {

super(Bitmap.getBitmapResource(strOffFocus), style);

this.actionCommand = actionCommand;
bitmapOnFocus = Bitmap.getBitmapResource(strOnFocus);
bitmapOffFocus = Bitmap.getBitmapResource(strOffFocus);
width = bitmapOnFocus.getWidth();
height = bitmapOnFocus.getHeight();

}

protected void layout(int maxWidth, int maxHeight) {
setExtent(Math.min(width, maxWidth), Math.min(height, maxHeight));
}

protected void drawFocus(Graphics graphics, boolean on) {
// Don't draw the default focus
}

public boolean isFocusable() {
return true;
}

protected void paint(Graphics graphics) {

if (isFocus()) {
graphics.drawBitmap(0, 0, getWidth(), getHeight(), bitmapOnFocus,
0, 0);
} else {
graphics.drawBitmap(0, 0, getWidth(), getHeight(), bitmapOffFocus,
0, 0);
}
}

protected void onFocus(int direction) {
super.onFocus(direction);
invalidate();
}

protected void onUnfocus() {
super.onUnfocus();
invalidate();
}

 

}

Please use plain text.
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850

Re: Issue in Button Field Listener

I reviewed your code, its great but without navigation click how can we invoke listener for TwoBitmapCustomField ?
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Issue in Button Field Listener

This is a well-known issue - when you touch a focusable field on the screen, that field first receives focus and then processes the "click" event. However, if you touch outside of any focusable fields, the currently focused one receives the event.

 

If you want to modify this behaviour, override touchEvent on the ButtonField level. If the event is CLICK and one of the X and Y of the touch is ouside of (0, getWidth()) or (0, getHeight()), respectively, return false; otherwise return super.touchEvent.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850

Re: Issue in Button Field Listener

[ Edited ]

Thank you arkadyz for useful suggestion, also I refered your  suggestion on link and cleared on Touch event

 

http://supportforums.blackberry.com/t5/Java-Development/Touch-event-is-working-outside-the-buttons/m...

 

Also Thank you milanvishal

Please use plain text.