Search This Blog

Thursday, 29 November 2012

How to handle the navigation click in blackberry

Hello friends,
                Here it is , in my previous post i told you about doing something on touchevents on any i am giving you the code which will handle click events on anyfield whether touch screen or no touch device....

Suppose we have a bitmapfield which we want to use as a button...we have two png's "abc.png" and for rollover we have "abcR.png"

So here it goes....


First we initialize the bitmap field like this...

BitmapField _button;

in construstor:

 _button = new BitmapField(){
public int getPreferredWidth(){
return 22;
public int getPreferredHeight(){
return 21;
public boolean isFocusable(){
return true;
public void onUnfocus(){
protected void drawFocus(Graphics graphics, boolean on) {
      XYRect focusRect = new XYRect();
           if (on) {
            graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
            graphics.drawBitmap(focusRect.x, focusRect.y, focusRect.width, focusRect.height,Bitmap.getBitmapResource("abcR.png"), 0,0);
//           this.setBitmap(Bitmap.getBitmapResource("help_rollover.png"));
public void layout(int maxWidth,int maxHeight){
super.layout(getPreferredWidth(), getPreferredHeight());


Now we will override the navigation click function and identify the field and do some action there:

public boolean navigationClick(int status,int time){
Field _focus = this.getLeafFieldWithFocus();
if(_focus instanceof BitmapField){
BitmapField _bitmap = (BitmapField)_focus;

//Do something....
return true;
return false;

Thsi will make your bitmap clickable whether its a touch event on that bitmap field on its a trackpad click....but only when this bitmap is in focus.....

Ask for any queries....

No comments:

Post a Comment