How to make a blackberry BitmapField non focusable in runtime

102 Views Asked by At

How to make a blackberry BitmapField non-focusable in runtime? I want make it dimmed based on a certain event.

2

There are 2 best solutions below

0
On

Extend the BitmapField to override the isFocusable() method like this:

public class FocusableBitmapField extends BitmapField {
    //Default value depending on whether you want it that way.
    private boolean focusable = true;

    public boolean isFocusable() {
        return focusable;
    }

    public boolean setFocusable(boolean focusable) {
        this.focusable = focusable;
    }
}
1
On

Most of times this works:

field.setEditable(false);

You can also create a non-focusable field by passing the style flag Field.NON_FOCUSABLE or Field.FOCUSABLE to the constructor, but once instantiated you cannot change it's focusable state. Even if you could, then the field won't look "dimmed" or "disabled", but simply the focus will jump to the next focusable field after it. An example of this are non-focusable label fields.

UPDATE: This would work for built in fields like EditFields, Checkbox, RadioButtons, etc. In your case, this does not work since a BitmapField is not "editable", it's a read only field. You can make a trick like @adwiv answer shows, but the "disabled" or gray overlay you'll have to implement it yourself.