PopupList

The PopupList API allows MIDlets to create pop-up lists and populate them with list items.

MIDlets can use the PopupList API to:

  • Create a PopupList and populate it with PopupListItem (including contextual menu PopupLists up to three levels deep)

  • Add and remove PopupListItems from an existing PopupList

  • Receive a notification whenever a PopupListItem is selected or the PopupList is dismissed

The lifecycle of a PopupList is dependent on the current Displayable. A PopupList can only be displayed on top of certain Displayables. A PopupList can only have a Form or a Canvas as a parent.

The PopupList API supports the following types of lists:

  • Contextual menu

    This is the default list type and does not have a header. It can be nested.

  • List dialog

    The list dialog has a header. It cannot be nested.

A PopupListItem can be of the following types:

  • Text

  • Text and icon

  • Text and checkbox

  • Text, icon, and checkbox

API Contents

The PopupList API consists of the following classes and interface (packaged as part of the Nokia UI API):

  • PopupList

    Use the PopupList class to create a pop-up list, append and insert list items, and remove items from the list. You can create the contextual menu type PopupList or the dialog type PopupList using the appropriate constructor.

  • PopupListItem

    Use the PopupListItem class to create list items to add to the PopupList. You can create the different types of PopupListItems using the appropriate constructor.

  • PopupListListener

    Use the PopupListListener interface to implement a listener for receiving a notification when a list item is selected or a list is dismissed.

For information about the Exceptions defined in the PopupList API, see the PopupList API reference.

The PopupList API is supported since Nokia UI API 1.6.

Device Compatibility

The PopupList API is supported on Series 40 devices with Java Runtime 2.0.0 for Series 40 or newer.

Using the PopupList API

To create a PopupList and populate it with PopupListItems:

  1. Create a PopupList:

    • To create a contextual menu:

      PopupList popupList = new PopupList();

      Contextual menu is the default list type, which is instantiated by the default constructor.

      You can also create a contextual menu by specifying the type.

      PopupList popupList = new PopupList(“Contextual Menu”, PopupList.CONTEXTUAL_MENU);
    • To create a list dialog:

      PopupList popupList = new PopupList("Header",PopupList.LIST_DIALOG);
  2. Create a PopupListItem:

    • To creating a PopupListItem with text:

      PopupListItem popupListItem = new PopupListItem("Text");
    • To create a PopupListItem with text and an icon:

      PopupListItem popupListItem = new PopupListItem("Text & Icon", icon);
    • To create a PopupListItem with text and a checkbox:

      PopupListItem popupListItem = new PopupListItem("Text & Marking", true);
    • To create a PopupListItem with text, an icon and a checkbox (which is not selected):

      PopupListItem popupListItem = new PopupListItem("Text & I & M", icon, true, false);
  3. Add the PopupListItem to the PopupList using the PopupList.appendItem method:

            try {
                list.appendItem(popupListItem);
            } catch (PopupListException e) {
            }
  4. Register a PopupListListener using the PopupList.setListener method:

    popupList.setListener(popupListListener);
  5. Implement the PopupListListener by defining the itemSelected and listDismissed methods:

        public void itemSelected(PopupList pl, PopupListItem pli) {
            System.out.println("itemSelected on list "+pl+" item is "+pli);
            if (pli == item1) {
                System.out.println("Clicked");
                item1.setText("Clicked"+(count++));
            } else if (pli == item11) {
                  PopupListItem newItem = new PopupListItem("Inserted "+(count++));
                  pl.insertItem(newItem, 1);
    /*            if (display.getCurrent() == canvas) {
                    display.setCurrent(form);
                } else {
                    display.setCurrent(canvas);
    
                }
     */
            } else if (pli == item31) {
                item3.setText("changed "+count++);
                LCDUIUtils.setCurrent(display, null, null);
            } else if (pli == item3) {
                fullscreen = !fullscreen;
                System.out.println("fullscreen = "+fullscreen);
                canvas.setFullScreenMode(fullscreen);
            } else if (pli == item311) {
                // none
                list3.setTailStyle(PopupList.TAIL_NONE);
            } else if (pli == item312) {
                // left
                list3.setTailStyle(PopupList.TAIL_LEFT);
            } else if (pli == item313) {
                // right
                list3.setTailStyle(PopupList.TAIL_RIGHT);
            } else if (pli == item314) {
                // parent
                list3.setTailStyle(PopupList.TAIL_PARENT);
            } else if (pli == removeFirst1) {
                if (pl.size() > 0) {
                    pl.removeItemAt(0);
                }
            } else if (pli == removeFirst2) {
                if (pl.size() > 0) {
                    pl.removeItemAt(0);
                    if (list2.size() > 0)list2.removeItemAt(0);
                    list5.appendItem(new PopupListItem("Added"));
                }
            }
        }
        public void listDismissed(PopupList pl) {
            System.out.println("Popuplist Dismissed "+pl);
    //        pl.setVisible(false);
        }