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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
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();
}

 

}

Trusted Contributor
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Issue in Button Field Listener

I reviewed your code, its great but without navigation click how can we invoke listener for TwoBitmapCustomField ?
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: 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!
Trusted Contributor
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

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