0

I have a problem with bitmapfield. I'm trying to have a click event on a Bitmap field.

It is working so far, but the problem is event is generating anywhere on the screen while i'm setting it on a particular field. As my app has multiple bitmaps on the same screen, it is being tough to manage them.

Here is my piece of code:

private BitmapField _HeaderBitmap =new BitmapField( Bitmap.getBitmapResource   ("headerImg.png")); 
final private Bitmap _secondHeaderBitmap = Bitmap.getBitmapResource("connect.PNG");
private BitmapField signup =new BitmapField (Bitmap.getBitmapResource("sign-up-btn.png"),BitmapField.FOCUSABLE);

protected boolean navigationClick(int status, int time)
{ 
   if (signup.isFocus())
     UiApplication.getUiApplication().pushScreen(new signupScreen());

   return true;
}
Mat
  • 202,337
  • 40
  • 393
  • 406
zoya.
  • 51
  • 1
  • 8
  • It may Help you am not sure.. Field field = getFieldWithFocus(); if(field instanceof BitmapField ){ and then again check with signup – Jisson Apr 18 '11 at 09:07
  • i have tried it also...lyk this but the problem is same.. private BitmapField signup =new BitmapField (Bitmap.getBitmapResource ("sign-up-btn.png"),BitmapField.FOCUSABLE); protected boolean navigationClick(int status, int time) { Field f=getFieldWithFocus().getLeafFieldWithFocus(); if (f==signup) { UiApplication.getUiApplication().pushScreen(new signupScreen()); } return super.navigationClick(status, time); } – zoya. Apr 18 '11 at 09:47

1 Answers1

1

You can just override the navigationClick() on the BitmapField itself.

private BitmapField signup =new BitmapField (Bitmap.getBitmapResource("sign-up-btn.png"),BitmapField.FOCUSABLE) {
    protected boolean navigationClick(int status, int time) {
        if((status & KeypadListener.STATUS_TRACKWHEEL) == KeypadListener.STATUS_TRACKWHEEL || (status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY) {    
            fieldChangeNotify(1);
            return true;
        }
        return super.navigationClick(status, time);
    }

}

And then attach a FieldChangeListener to it. In your fieldChanged() method just check that context == 1. There is some additional checking on status you can do before firing the fieldChangeNotify() but this is the basic part of getting your BitmapField to act like a button. Also, you might was well create your own class from this (rather than creating an anonymous class) so you can use it in the future.

jprofitt
  • 10,874
  • 4
  • 36
  • 46