You Are Here:

Community: Wiki

This page was last modified on 21 October 2009, at 18:42.

MIDP's User Interface Hierarchy: List

From Forum Nokia Wiki

Contents

Overview

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).

Introduction

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.


File:ListMULTIPLE.jpg

  • List.EXCLUSIVE: The user can select just one element at a time. Similar to a HTML RadioButton tag.


File:ListEXCLUSIVE.jpg

  • List.IMPLICIT: The user can select just one element at a time.


File:ListIMPLICIT.jpg

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

File:ListTable.png

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:

File:ElementsImagesList.png

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).

Other links

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia