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