Disable button focus on a blackberry application (Java)

by Rod
15. March 2010 01:12

As a usual .net developer, I’ve been used and spoiled with various methods that are real time savers!

And to be honest while developing a blackberry application I’ve come across a lot of things that need a bit more of work in the Blackberry Java SDK.

Let’s say you want to disable a button on your application and not permit the button selection.

You see you can enable/disable the focus on the button, but you can enable / disable the button to be clicked/

So how do you disable the selection?

You might be satisfied by just removing and re-adding the button into the UI.

But here’s a simple way to overcome this small obstacle :

First of all you need to create a new class that extends from “ButtonField” :

   1:  public class MyCustomButton extends ButtonField 
   2:  {
   3:  }

After adding the constructors you need, you have to override isFocusable method :

If my button is disabled I don’t want it to be focusable so we’d return the isEditable() method.

So the class right now looks like this :

   1:  public class MyCustomButton extends ButtonField 
   2:  {
   3:     public MyCustomButton()
   4:      {
   5:          super();
   6:      }
   7:   
   8:      public MyCustomButton(long style)
   9:      {
  10:          super(style);
  11:      }
  12:   
  13:      public MyCustomButton(String label)
  14:      {
  15:          super(label);
  16:      }
  17:   
  18:      public MyCustomButton(String label,long style)
  19:      {
  20:          super(label,style);
  21:      }
  22:   
  23:      public boolean isFocusable()
  24:      {
  25:          //this is where all the magic happens.
  26:         //if my button is disabled then i don't want it to be focusable
  27:          return isEditable();
  28:      }
  29:   
  30:  }

So in order to disable our button right now and disable the focus all we have to do is call the setEditable() method and send false in parameter.

   1:  MyCustomButton btnHello = new MyCustomButton();
   2:  btnHello.setEditable(false);

Tags: ,

general development

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Rodrigue Hajjar

About the author

.NET Developer.

.Supinfo Student.

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar