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
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000
My Carrier: none
Accepted Solution

how to enable / disable some fields based on checkbox value

This is probably a stupid question, but I was not able to find the trivial solution (I am pretty new to BlackBerry UI)

 

Example scenario:

 

UI screen with two component 

checkbox: "Run every day"

time field: "at hh:mm"

 

If checkbox is checked,  time field should be enabled. If checkbox is not checked,  time field should be disabled.

 

 

I was not able to find a simple solution. The workaround is to delete all components and recreate them with different style (Field.NON_FOCUSABLE | Field.READONLY), but there are major drawbacks:

  1. It's pretty messy to keep the currently entered value (if user has modified the time field and clicks two times on checkbox, I'd like to have same value and the field should be dirty)
  2. It gets more messy when you have more complicated logic (panels inside panels which should be enabled / disabled based on all parent checkboxes) 

Any ideas ? :smileyhappy:

 

Thanks in advance !


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: how to enable / disable some fields based on checkbox value

Some times Ago I was Also Find this solution.

But BlackBerry Does not provide Enable/ Disable Method.

But Ucan Delete Or add the controlls on the screen At runtime.

Please use plain text.
Developer
Developer
CMY
Posts: 1,122
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: how to enable / disable some fields based on checkbox value

The way I handled this was to have custom methods in the fields that allow me to set a disabled state and then override the TouchEvent, NavigationMovement, and NavigationClick methods to check for this variable and just return true if it is set. This will take care of the FieldChanged and Focused states to make them unable to be activated.

Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000
My Carrier: none

Re: how to enable / disable some fields based on checkbox value

Ok, subclassing components and taking care of all UI events + rendering - we need different view when component is disabled - is another approach (which I forgot to include in my original post).

 

This approach is also somewhat messy - at least for the rendering ...

 

Any other ideas ? It seems strange to not have such basic functionality in core API ...


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to enable / disable some fields based on checkbox value

[ Edited ]

You can, for all the Fields I have ever wanted to do it on (which is not all Fields so perhaps there are Fields for which this does not work), set 'Editable'.  What I have done in places, is have isFocusable() check isEditable(), and then the user can't touch the Field if they are not allowed to Edit it.  I don't actually like this approach because I like to give the user to opportunity to cut/paste or at least scroll with some degree of smoothness, but sometimes it is all you need. 

 

You can also override isEditable() to check whatever you want. 

 

Regarding the API looking different, yes you are right, it doesn't appear (at least in Fields that I have tried) that not being editable or not being focusable changes the appearance.  So you need to override paint in some way if your want to indicate this state.

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: how to enable / disable some fields based on checkbox value

Agree wit Peter...we also override paint() and set the globalAlpha() value to 60% in order to give the control the "disabled" look.

 

Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000
My Carrier: none

Re: how to enable / disable some fields based on checkbox value

Thanks to everybody that contributed !

 

I will accept one random comment as "answer" to close this thread, please don't be offended


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000
My Carrier: none

Re: how to enable / disable some fields based on checkbox value

Just for the record - I decided to go with system styles and partial / full screen regeneration.

 

Main reason is that paint cannot be customized well in some situations - for example in OS 5.0 you cannot change text color for ColorObjectChoiceField and setting global alpha damages the combo image.

 

 


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Regular Contributor
Plato
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000
My Carrier: none

Re: how to enable / disable some fields based on checkbox value

Just for the record - if any future visitor is interested

 

I found a workaround for this issue:

 

>  and setting global alpha damages the combo image.

 

What one needs to do is to 1. do the normal render and then 2. render alpha rect on top of the component. There is another thread regarding this approach:

 

http://supportforums.blackberry.com/t5/Java-Development/Rendering-Issues-with-setGlobalAlpha/m-p/117...


-----
A good decision is based on knowledge and not on numbers.
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to enable / disable some fields based on checkbox value

Very useful - thanks

Please use plain text.