Would you like to tell us how we are doing?

You bet No thanks

Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Radio buttons

Use radio buttons to indicate a set of mutually exclusive but related choices.

Users can perform the following action with radio buttons:

Action

BlackBerry devices with a trackpad only

BlackBerry devices with a touch screen and a trackpad

Select a radio button.

Press the Space key or click the trackpad.

  • Tap the item.
  • Press the Space key.
  • Click the trackpad.

This screen shows a radio button.

Best practice: Implementing radio buttons

  • Use radio buttons for two or more choices when space is not an issue. If space is an issue, consider using a drop-down list instead.
  • Use the RadioButtonField class to create radio buttons.
  • Verify that the content for radio buttons remains static. Content for radio buttons should not change depending on the context.
  • Do not start an action when users select a radio button. For example, do not open a new screen.
  • Align radio buttons vertically.
  • Group and order values logically (for example, group related radio buttons together or include the most common values first). Avoid ordering radio buttons alphabetically; alphabetical order is language specific.

Guidelines for labels

  • Use clear, concise labels. Verify that the label clearly describes what occurs when users select the radio button. If the labels are too long, they wrap.
  • Place labels on the right side of radio buttons.
  • Use sentence case capitalization.
  • Do not use end punctuation.

Code sample: Creating a radio button

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

//Create the application framework by extending the 
//UiApplication class. In main(), create an instance of 
//the new class and invoke enterEventDispatcher() to 
//enable the application to receive events. In the 
//application constructor, invoke pushScreen() to 
//display the custom screen for the application. 
public class MyUi extends UiApplication 
{ 
    public static void main(String[] args) 
    { 
        MyUi theApp = new MyUi(); 
        theApp.enterEventDispatcher(); 
    } 
    public MyUi() 
    { 
        pushScreen(new MyUiScreen()); 
    } 
}

//Create the custom screen for the application by extending the 
//MainScreen class. In the screen constructor, invoke setTitle() 
//to specify the title for the screen.
class MyUiScreen extends MainScreen 
{
    public MyUiScreen() 
    {
        setTitle("UI Component Sample");

//In the screen constructor, create a group of radio buttons by
//using the RadioButtonGroup class. Create the radio buttons
//that you want to add to the group by using the RadioButtonField 
//class. In the RadioButtonField constructor, specify the label for
//the radio button, the group, and a Boolean value to indicate the 
//default selection (for example,true indicates that by default the
//radio is selected). Invoke add() to add the radio buttons to the screen. 
        RadioButtonGroup rbg = new RadioButtonGroup();
        add(new RadioButtonField("Option 1",rbg,true));
        add(new RadioButtonField("Option 2",rbg,false));
    }

//To override the default functionality that prompts the user to
//save changes before the application closes, in the extension of the 
//MainScreen class, override the MainScreen.onSavePrompt() method. 
//In this example, the return value is true, which indicates that 
//the application does not prompt the user before closing.
    public boolean onSavePrompt()
    {
        return true;
    }
}