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
Contributor
Posts: 13
Registered: ‎10-01-2010
My Device: Storm 9500

Visual State Disabled

Hi guys i have a question ..

 

Iam using a picturescrollfield with some buttons below. I create this UI and want that a button is disabled when some criteria is fullfilled. So i make some code to put in the fieldchange and change the visual state to disabled if criteria is fullfilled. All this works fine.

But my Problem is when i create the ui, the buttons arent disabled. They are just disabled when i scroll and make the fieldchange begin. So i decided to put something like url_button.setVisualState(ButtonField.VISUAL_STATE_DISABLED) after the button is added to the fieldmanager. But this affects nothing. If i change the label it works, but change the visual state dont affect the button.

 

Anybody knows why and how to change ?

New Contributor
Posts: 8
Registered: ‎03-22-2011
My Device: Blackberry 9800
My Carrier: O2

Re: Visual State Disabled

[ Edited ]

Good question, I am also confused with this matter, could you please give us a hint on that?

Bear in mind that I am using the default buttons provided. I have seen some workarounds by creating custom buttons, but I was wondeing if with the newer apis, it would be simpler to implement enable/disable functionality of a button.

Highlighted
Contributor
Posts: 28
Registered: ‎07-29-2010
My Device: Torch 9850
My Carrier: Verizon

Re: Visual State Disabled

[ Edited ]

Using the setEditable method should achieve what you are looking for.

 

For example:

 

// Disable the button
myButton.setEditable(false);

// Enable the button
myButton.setEditable(true);

 The button will still be displayed on the UI, however, it will not be clickable, just disabled.

 

Russ.

New Contributor
Posts: 8
Registered: ‎03-22-2011
My Device: Blackberry 9800
My Carrier: O2

Re: Visual State Disabled

Thanks for the solution, Russ!

 

Just a curiosity. SetVisualState why is it used for then?

Contributor
Posts: 28
Registered: ‎07-29-2010
My Device: Torch 9850
My Carrier: Verizon

Re: Visual State Disabled

Glad I could help!  Please mark the topic as solved by the way if my answer was sufficient.

 

As for setVisualState, the docs say:

 

setVisualState

public final void setVisualState(int visual)

Sets this field's current visual state, which can be subsequently accessed via Field.getVisualState().

 

Parameters: visual - One of the following visual states: Field.VISUAL_STATE_NORMALField.VISUAL_STATE_ACTIVE,Field.VISUAL_STATE_FOCUSField.VISUAL_STATE_DISABLEDField.VISUAL_STATE_DISABLED_FOCUS. Since: BlackBerry API 4.6.0

 

Looks like, from the states available, it allows you to directly choose a state of the field rather than letting the UI determine the correct state due to focus and editablilty.  I haven't made use of this myself, so someone else please chime in if you have any insight. Russ.