How can I push a new View with onSelect() by using of a Menu2 ?

Former Member
Former Member

Here is my code where I define the instructions for each Item :

class MenuTestMenuDelegate extends WatchUi.Menu2InputDelegate {

    function initialize() {
        Menu2InputDelegate.initialize();
    }

    function onSelect(item) {
        if (item != :Item1) {
            System.println("Item 1");
            WatchUi.pushView(new Rez.Menus.AuxMenu(), new AuxMenuDelegate(), WatchUi.SLIDE_UP);
        } else if (item == :Item2) {
            System.println("Item 2");
        } else if (item == :Item3) {
            System.println("Item 3");
        }
    }
}

Thank you in advance for your precious collaboration. 

  • Hi,

    There's a couple of ways to do this but I generally do this in onSelect. The DrawableMenuTitle just does some funky icon management and could be as simple as :title="Menu title"

    Note your first if test might be in error as this means if the value is Item1 it is skipped

    if (item == "XXXX") {

    // Generate a new Menu for mainmenu
    var menu = new Ui.Menu2({:title=>new DrawableMenuTitle("Main", false)});
    // add items
    menu.addItem(new Ui.MenuItem("Test type", null, "t", null));
    menu.addItem(new Ui.MenuItem("Source", null, "s", null));
    Ui.pushView(menu, new MainMenuDelegate(), Ui.SLIDE_IMMEDIATE );

    } else.... next menu structure

  • if(item=="XXXX")

    Will always be false You don't use '"==" with strings.  you use equal("XXXX");

    Like:

     if( item.getId().equals("XXXX") ) {

  • Correct as always Jim. That is what I do in my code. Just replied too quickly.

  • Former Member
    Former Member over 4 years ago in reply to jim_m_58

    Hi, I tried it and it works.

    Thank you very much :).