Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon
Accepted Solution

Disableing a field

Is there any way to disable a field so that it can't be edited or focused? I have tried setVisualState(ButtonField.VISUAL_STATE_NORMAL) for some buttons I have but they are only temporarily disabled (or at least look disabled).
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Disableing a field

void setEditable(boolean)

and

boolean isFocusable()

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Disableing a field

That partially works but the FieldChangeListener is still called. Is there a way to modify the field so that the FieldChangeListener is not called?
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Disableing a field

Hi rcmaniac25,

 

Try something like this:

     

        btn.setFocusable(false);

    then the btn will never get the focus. So fieldChangeListener will never be called.

    and also comment this line if you have that in your code

        //btn.setChangeListener(this);

 

Regards

Bikas 

  

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Disableing a field

Thank you but where is setFocusable(boolean)? It does not appear to be in a field.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Disableing a field

Hi rcmaniac25,

 

Sorry i copied setFocusabled(false) from my CustomButton class. This is not present in the api.

 

You can try with this:

 

ButtonField btn = new ButtonField("Button", Field.NON_FOCUSABLE);

and do not add listener to the field

//btn.setChangeListener(this);

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Disableing a field

[ Edited ]
That works but is there a way to do it with a field that has already been created? I understand why you should not add the listener but I am trying make quick changes with the least amount of variables to store, if that makes sense.
Message Edited by rcmaniac25 on 05-14-2009 05:51 PM
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Disableing a field

Override the boolean isFocusable() of the field to return isEditable(), when you have a need to set the property of a field to be unfocusable, then call setEditable(false); , this will solve your question..

 

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Regular Contributor
Posts: 71
Registered: ‎03-24-2010
My Device: 9550
My Carrier: Vodaphone

Re: Disableing a field

[ Edited ]

If you want to have a ButtonField which can be disable/enable

1. add your own method

setEnable(flag).

2. override from ButtonField the following method

- isFocusable {return flag }

- notifyFieldChange { call super.notifyFieldChange only if flag= true}

 

I don't understand why I have to write those code. Smiley Sad.

RIM is supposed to provide us those code in their API, all serious app must have this kind of button.