开发者

Click event on a BitmapField

开发者 https://www.devze.com 2023-02-26 19:37 出处:网络
I have a problem with bitmapfield. I\'m trying to have开发者_运维知识库 a click event on a Bitmap field.

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;
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消