Package totalcross.ui

Class PopupMenu


  • public class PopupMenu
    extends Window
    Creates a popup menu with a single line list and some radio buttons at right, like in the Android combobox styles. This is a sample of how to use it:
       String[] items =
       {
             "Always",
             "Never",
             "Only in Silent mode",
             "Only when not in Silent mode",
             "Non of the answers above",
       };
       PopupMenu pm = new PopupMenu("Vibrate",items);
       pm.popup();
     
    A PRESSED event is sent when an item is selected. Note: the colors must be set before the control's bounds are defined using setRect or add.
    • Field Detail

      • cancelString

        public static java.lang.String cancelString
        The string of the button; defaults to "Cancel"
      • dataCol

        public int dataCol
        If the items is a String matrix (String[][]), this field sets the column that will be shown.
      • itemCount

        public int itemCount
        Sets the number of elements should be used from the items array passed in the constructor. Defaults to items.length.
      • checkColor

        public int checkColor
        The check color used to fill the radio button used in Android. Defaults to the fore color.
        Since:
        TotalCross 1.3
      • enableSearch

        public boolean enableSearch
        Set to true BEFORE popping up the window to enable search on the items of this PopupMenu. Note that it only works if the items are ORDERED.
        Since:
        TotalCross 1.5
      • enableCancel

        public boolean enableCancel
        Set to false BEFORE popping up the window to disable the Cancel button.
        Since:
        TotalCross 1.65
      • keepIndexOnCancel

        public boolean keepIndexOnCancel
        Set to true to keep the selected index unchanged if user press the Cancel button
        Since:
        TotalCross 2.0
    • Method Detail

      • initUI

        public void initUI()
        Description copied from class: Container
        Called to initialize the User Interface of this container. This differs from the onAddAgain method by that this method is called only once, at the first time the control is added to the parent. When the container is being setup, the initUI method is called; then, the onAddAgain is called every time the container is added again.
        Overrides:
        initUI in class Container
      • reposition

        public void reposition()
        Description copied from class: Control
        Reposition this control, calling again setRect with the original parameters.
        Overrides:
        reposition in class Control
      • setSelectedIndex

        public int setSelectedIndex​(int index)
        Selects the given index.
      • getSelectedIndex

        public int getSelectedIndex()
        Returns the selected index when this window was closed or -1 if non was selected
      • onPopup

        protected void onPopup()
        Setup some important variables
        Overrides:
        onPopup in class Window
      • postUnpop

        protected void postUnpop()
        Description copied from class: Window
        Placeholder called after the unpop is done and after the repaint of the other window. The default implementation does nothing.
        Overrides:
        postUnpop in class Window
      • onEvent

        public void onEvent​(Event event)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • setCursorColor

        public void setCursorColor​(int c)
        Sets the cursor color. By default, it is based in the background color