List

List is a user interface component that occupies the whole main pane of the screen and allows the user to select one or multiple items from a predefined set. The List layout varies based on four attributes:

When a List becomes the foreground Displayable, the currently selected List element becomes automatically focused. Row elements are composed of a text part, an optional icon and an optional font attribute. A List is almost similar to the Form component ChoiceGroup and they both have a common Choice interface.

Lists come in three different configurations: IMPLICIT, MULTIPLE and EXCLUSIVE. A common usage for a List is a MIDlet main menu.

Figure 21: A simple MULTIPLE List

Source code for the example:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ExampleList extends MIDlet implements CommandListener {
    private List ls;
    private Command exit;
 
    public ExampleList() {
        //List(label,type,items,Images)
        ls = new List("Multiple list", List.MULTIPLE, new String[] {"Choice 1", "Choice 2", "Choice 3", "Choice 4"}, null);
        exit = new Command("Exit", Command.EXIT, 1);
        ls.addCommand(exit);
        ls.setCommandListener(this);
    }      
    public void startApp() {
        Display display=Display.getDisplay(this);
        display.setCurrent(ls);
    }      
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command command, Displayable displayable) {
        if (command == exit) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}

For more information about S60-specific List features, see List implementation notes.