Creating a list style button field

A list style button field is a field that has a similar appearance to a row in a list, but functions as a button. You can use the ListStyleButtonField class to create a list style button field that uses the entire width of its manager, and can optionally include two icons. An icon can appear to the left of the text of the button, and another icon can appear to the right of the text. The right icon is justified to the right side of the field. You can provide style bits when you create a ListStyleButtonField object to specify the style of the text of the button. For example, you can specify the FIELD_RIGHT style bit of the Field class to align the text to the right within the field.

You might use a ListStyleButtonField object to indicate to a BlackBerry® device user that clicking the button provides additional options. This approach might be useful in a set of options screens for your application.

Create a list style button field

  1. Import the required classes and interfaces.
    import com.blackberry.toolkit.ui.component.ListStyleButtonField;
    import net.rim.device.api.system.Bitmap;
  2. Create new Bitmap objects to represent the left and right icons for each ListStyleButtonField object on your screen. Invoke the static Bitmap.getBitmapResource() to retrieve a Bitmap object from an image resource file. In this task, each ListStyleButtonField object uses the same icon on the right side of the button, but different icons on the left side of the button.
    Bitmap buttonRight = Bitmap.getBitmapResource( "rightImage.png" );
    Bitmap button1left = Bitmap.getBitmapResource( "leftImage1.png" );
    Bitmap button2left = Bitmap.getBitmapResource( "leftImage2.png" );
    Bitmap button3left = Bitmap.getBitmapResource( "leftImage3.png" );
  3. Create new ListStyleButtonField objects to represent the buttons. Specify the appropriate Bitmap objects in the ListStyleButtonField constructor. In this task, a value of 0 is specified as the style parameter, indicating that the default style should be used for the text of the button.
    ListStyleButtonField firstField = new ListStyleButtonField( button1left, "Files", buttonRight, 0 );
    ListStyleButtonField secondField = new ListStyleButtonField( button2left, "Photos", buttonRight, 0 );
    ListStyleButtonField thirdField = new ListStyleButtonField( button3left, "Videos", buttonRight, 0 );
  4. Add the ListStyleButtonField objects to the screen.
    add( firstField );
    add( secondField );
    add( thirdField );
Previous topic: Create a button field set

Was this information helpful? Send us your comments.