Question

I'm working on adding a BitmapField to my Blackberry project.

I implemented my class with a FieldChangeListener and added the FieldChangeListener method to my class. I even added a setChangeListener to that particular Bitmap Field, but it's not responding to click events.

How do I fix this?

Was it helpful?

Solution

First, BitmapField is not focusable by default, so you'll need to subclass and override isFocusable to fix that. Then override navigationclick to fire a fieldChanged event. Code snippet for a minimum field:

import net.rim.device.api.ui.component.BitmapField;

public class ClickableBitmapField extends BitmapField {
    public boolean isFocusable() {
        return true;
    }

    protected boolean navigationClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }
}

In addition to this, you may want to provide some indication of when your field is in focus (unless you only care about touch-screen devices). The default implementation will just draw a highlight on any transparent areas of your bitmap. You can change this by overriding drawFocus, and maybe onFocus and onUnfocus to change the bitmap you display when the focus state changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top