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
Developer
Posts: 484
Registered: ‎07-17-2008
My Device: Not Specified
Accepted Solution

Disable RadioButtonField

BlackBerry Storm / 4.7.0.75

 

Prior to 4.7 I was using Field.NON_FOCUSABLE to prevent a user from setting a RadioButtonField.

 

This doesn't work on the storm.  While it does prevent focusing, the user can still select the button by clicking it.

 

I could remove the RadioButtonField from the group, but I'd like it to be "grayed out" so to speak.

 

Is there any way to do this?

 

Thanks,

 

Jon

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Disable RadioButtonField

[ Edited ]

To make this radio button field gray and prevent user from selecting it do the following:

 

Create new class that extends RadioButtonField.

 

Add new property to the new class, say it is:

 

private boolean isEnabled = true; // by default - enabled

 

override paint() and setSelected() methods.

 

protected void paint(Graphics graphics) {
if (isEnabled) {
// if enabled - drawing in BLACK
graphics.setColor(Color.BLACK);
} else {
// if field is not enabled - drawing in GRAY
graphics.setColor(Color.GRAY);
}

super.paint(graphics);
}

public void setSelected(boolean selected) {
// if field is enabled - passing parameter value
// if not enabled - passing false
final boolean flag2set = isEnabled?selected:false;
super.setSelected(flag2set);
}

 

Usually, when a radio button goes to unavaliable state - the application removes it from the screen. It is a common practice in User Interface. Grayed fields usually used for Checkboxes, but not for RadioButtons.

 

Unavailable but visible RadioButton may confuse a user. Just my humble opinion Smiley Happy

Message Edited by tbilisoft on 31-12-2008 06:33 AM