Take the 2-minute tour ×

I am using bitmap button field in advanced ui examples. By default no method is working for disabling the button in 5.0 jre, so i have added the below code for disabling and then disabling functionality of the button is working but setchangelistener is not working that is my problem .. here is my code that i added for disabling the button..please check. do i need to change anything in invoke action method?

 public boolean isDisable() {
   return isDisable;

 public void setDisable(boolean isDisable) {
   this.isDisable = isDisable;

 public boolean isFocusable() {
   return isFocusable && !isDisable;

 public void setFocusable(boolean isFocusable) {
 this.isFocusable = isFocusable;

 protected boolean invokeAction(int action) {
   if (!isDisable){

       return true;

 public boolean setEnabled() {
   return false;
share|improve this question
your code is commented out (I assume it's not that way in the program, but it's still hurts my eyes), and your getEnabled() method is named setEnabled(). you haven't shown any setChangeListener() code, so we can't see how it's used. please add that, too, if you'd like us to see what's wrong with it. thanks. –  Nate Jul 12 '12 at 10:40
hi Nate.. if i added the code. in my ui class. button.setchange listener is not working –  user1427659 Jul 13 '12 at 7:00
those are the links for classes which i have used for adding the bitmap.. –  user1427659 Jul 13 '12 at 7:02
show 3 more comments

1 Answer

Here is a discussion on the BlackBerry forums about this.

What I've sometimes done is actually make use of the isEditable() property on Field objects, since editability and being enabled are somewhat similar concepts. If you really want to keep the separate isDisabled() code, that's fine. Just substitute that below where I use isEditable() (remembering to reverse the boolean ... that's one reason to always program in the affirmative ... make your method isEnabled() instead of isDisabled()).

So, instead of any of the code you posted above, I would just add this code to either BitmapButtonField, or BaseButtonField:

public boolean isFocusable() {
   return isEditable() && super.isFocusable();

and this in BitmapButtonField:

protected void paint( Graphics g ) {
   int oldAlpha = g.getGlobalAlpha();
   int index = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? FOCUS : NORMAL;
   if (!isEditable()) {
      g.setGlobalAlpha(100);  // alpha is 0 to 255, so this is 100/255
   g.drawBitmap( 0, 0, _bitmaps[index].getWidth(), _bitmaps[index].getHeight(), _bitmaps[index], 0, 0 );

And then, I can setup a change listener, or disable the button, like this in my manager class:

  BitmapButtonField btn = 
     new BitmapButtonField(Bitmap.getBitmapResource("button.png"),

  btn.setChangeListener(new FieldChangeListener() {
     public void fieldChanged(Field field, int context) {
        Dialog.alert("Button clicked!");
  btn.setEditable(false);   // this disables the button

But, understand, that if you disable a button, that means your change listener won't get called. That's kind of how it's supposed to work. The change listener is only called if the button's enabled and therefore clickable.

Also, note that in order to make the button look different when disabled (not editable), I override paint() to set a different alpha value when the button is disabled. You didn't mention that, so if you don't like it, you can certainly take it out.

share|improve this answer
add comment

Your Answer


