Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

MIDP's User Interface Hierarchy: List

From Wiki
Jump to: navigation, search

In the second part of the MIDP's User Interface Hierarchy series, we discussed about the TextBox MIDP's UI component (MIDP's User Interface Hierarchy: TextBox). In this third part I'll discuss about the Screen-based component called List (javax.microedition.lcdui.List).

Article Metadata
Created: thiagobrunoms (10 Oct 2009)
Last edited: hamishwillee (13 Aug 2013)


When we would like to show a list of values, the MIDP's UI LCDUI components provides, among other options, the List screen. The List screen can have the following types:

  • List.MULTIPLE: The user can select as many elements as possible. Similar to a HTML ComboBox tag.
  • List.EXCLUSIVE: The user can select just one element at a time. Similar to a HTML RadioButton tag.
  • List.IMPLICIT: The user can select just one element at a time.

In the following table we can see the main operations related to the List component.


Code Examples

To create a new List screen, you can extend the class List and define your own methods, such as:

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
public class MyList extends List {
* @param title The List's title
* @param listType The List's type: IMPLICIT, EXCLUSIVE or MULTIPLE

public MyList(String title, int listType) {
super(title, listType);
* @param title The List's title
* @param listType The List's type: IMPLICIT, EXCLUSIVE or MULTIPLE
* @param stringElements The List's initial elements
* @param imageElements The List's initial images related to each element

public MyList(String title, int listType, String[] stringElements,
Image[] imageElements) {
super(title, listType, stringElements, imageElements);

The following example shows how to use the MyList class:

d = Display.getDisplay(this); //gets the display reference
list = new MyList("List of Books", List.EXCLUSIVE); //selects the EXCLUSIVE List type
list.append("Book 1", null); //adds the "Book 1" element;
list.append("Book 2", null); //adds the "Book 2" element;
d.setCurrent(list); // shows the List

The former client example only creates a List with its name and type. However, if we would like create a List with initial elements, we could use the other constructor:

Display d = Display.getDisplay(this); //gets the display reference
//Creates a List (MyList) with initial elements and images
list = new MyList("List of Books", List.MULTIPLE, new String[]{"Book 1", "Book 2"}, new Image[]{new Image(...), new Image(...)});
d.setCurrent(list); // shows the List

Note that each image in Image[] belongs to each element in String[]. That is:


This third part of this series introduced the List UI component. The next part I will talk over about the Alert Screen-based component (MIDP's User Interface Hierarchy: Alert).

This page was last modified on 13 August 2013, at 06:21.
27 page views in the last 30 days.