×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    Question Lwuit - Composite Menu / Command ?

    Does anyone know how create a composite menu/command like this one: https://www.dropbox.com/s/o9kx7ihpkkj72lb/Menu.png

    Because command class doesn't have any method to include other commands - http://lwuit.java.net/javadocs/com/s...t/Command.html

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Lwuit - Composite Menu / Command ?

    Hi dhbellol and welcome to Nokia Developer Discussion Boards,

    Commands of type ITEM can be displayed as a context menu (pop up menu) by long pressing any list item. You only need to add the Commands to a list:

    Code:
            List list = new List("List", List.IMPLICIT);
            list.append("Item 1", null);
            list.append("Item 2", null);
            Command subItem1 = new Command("Sub Item 1", Command.ITEM, 1);
            Command subItem2 = new Command("Sub Item 2", Command.ITEM, 2);
            list.addCommand(subItem1);
            list.addCommand(subItem2);
            list.setCommandListener(this);
            Display.getDisplay(this).setCurrent(list);
    On a Form, you can set the context Menu to appear after long pressing a specific StringItem by adding Commands to that StringItem only. In this case, the Commands do not necessarily have to be of type ITEM:

    Code:
            Form form = new Form("form");
            StringItem item1 = new StringItem("Option 1", null);
            StringItem item2 = new StringItem("Option 2", null);
            form.append(item1);
            form.append(item2);
            
            item2.setItemCommandListener(this);
            Command subItem1 = new Command("Sub Item 1", Command.OK, 1);
            Command subItem2 = new Command("Sub Item 2", Command.OK, 2);
            item2.addCommand(subItem1);
            item2.addCommand(subItem2);
            
            Display.getDisplay(this).setCurrent(form);
    However in the above solutions, the context menu doesn't have a checkbox. In order to add a checkbox to a context menu, you need to use PopupLists. An example is this:

    Code:
            PopupList mainList = new PopupList();
            
            PopupList subList = new PopupList("Go to SubList", PopupList.CONTEXTUAL_MENU);
            
            PopupListItem i1 = new PopupListItem("item 1", null, true, false);
            PopupListItem i2 = new PopupListItem("item 2", null, true, true);
            subList.appendItem(i1);
            subList.appendItem(i2);
            mainList.appendItem(subList);
            mainList.setVisible(true);

Similar Threads

  1. LWUIT- adding back command to button
    By herahadi in forum Mobile Java General
    Replies: 0
    Last Post: 2013-03-07, 08:53
  2. What is the Back Command in LWUIT
    By aquinotricia in forum Mobile Java General
    Replies: 1
    Last Post: 2013-02-11, 00:32
  3. Command is not working on LWUIT Form Screen
    By pavanragi in forum Mobile Java General
    Replies: 1
    Last Post: 2012-08-12, 21:59
  4. how to implement command in lwuit.
    By debasish_cse05 in forum Mobile Java General
    Replies: 1
    Last Post: 2011-01-12, 11:42
  5. how to add first command on right and others in left in LWUIT
    By Manish_Bansal in forum Mobile Java General
    Replies: 12
    Last Post: 2010-08-17, 06:51

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •