BlackBerry 6.0 OS UI components - RichList

BlackBerry 6.0 OS UI components - RichList
Page content

Introduction

In this series of articles we’ll focus on the new User Interface components that BlackBerry 6.0 O.S. offers us so as to create enhanced UI applications.

The first UI component we talk about will be the RichList.

Basically, what RichList gives us that we didn’t have before is a way to create a basic list of elements with an image associated. This improvement makes us able to easily give a better look to our application, similar to what other mobile operating systems do.

Following is the simple code used to add a richlist to an application. As you probably have read previous articles, we will just focus the code on the RichList component creation.

The code

First of all we create the RichList object (myRichlist) .

Manager mainManager = getMainManager();

RichList myRichlist = new RichList(mainManager, true, 2, 1);

The RichList constructor’s arguments are used to build the shape of the final RichList component. The first space is the “Image Space” which is on the top left corner. It is assigned a square of 50 pixels by 50 pixels. The second space is the “Labels Space” which are strings that will appear to the right of the “Image Space”. Consider the “Labels Space” as a single column with several rows. The “Labels Space” assigns one row of space to each string. Consider the “Image Space” as a single column that spans a number of rows equal to the number of rows in the “Labels Space”. The third space is the “Descriptions Space” which are strings that will appear below both the “Image Space” and the “Labels Space”. The “Descriptions Space” assigns one row of space to each string. Consider the “Descriptions Space” as a series of rows that span the width of the “Image Space” column and the “Label Space” column.

So in our example, we are building a RichList with an image, two labels and one description.

Then we get the images from our resources (they have to have been previously added to the project).

Bitmap bitmap1 = Bitmap.getBitmapResource(“image1.png”);

Bitmap bitmap2 = Bitmap.getBitmapResource(“image2.png”);

Bitmap bitmap3 = Bitmap.getBitmapResource(“image3.png”);

After getting the images, we add the elements to the myRichlist using add method. This method adds an array of data to the bottom of the RichList. If the “Image Space” is being used, the first item in the array must be a Bitmap object. If the “Labels Space” is being used, the Strings that represent the labels should be placed in top-first order after the Bitmap object (or at the beginning of the array if there is no image being used). If the “Descriptions Space” is being used, the Strings that represent the descriptions should be placed in the array after the Bitmap (if any) and the label Strings (if any).

myRichlist.add(new Object[] {bitmap1, “label 1 – first item”, " label 2 – first item “, “Description of first item.”});

myRichlist.add(new Object[] {bitmap2, " label 1 – second item “, " label 1 – second item “, “Description of second item.”});

myRichlist.add(new Object[] {bitmap22, " label 1 – third item “, " label 1 – third item “, “Description of third item.”});

This would be a basic approach to the RichList component.

This post is part of the series: BlackBerry UI Development

Working with the user interface of BlackBerry 6 OS. Learn about different UI components and how to use them with some easy to follow code samples and snippets.

  1. BlackBerry 6.0 OS UI components - RichList
  2. BlackBerry 6.0 OS UI components - ToolBar
  3. BlackBerry 6.0 OS UI Components - Activity Indicator
  4. BlackBerry 6.0 OS UI Components - Progress Indicator
  5. BlackBerry 6.0 OS UI Components - Table