navigating with a menu

Hello everybody,

I want to show an menu, when the app is started and then navigate with that threw two options, which are referring to different layouts.

I defined it in the xml and it worked, but i cant call it in the onMenuItem Method with code, similar to this:

function onMenuItem(item as Symbol) as Void {
if (item == :item_1) {
switchToView(Rez.Layouts.loadFunctionOne(dc), null, WatchUi.SLIDE_IMMEDIATE);
} else if (item == :item_2) {
switchToView(Rez.Layouts.loadFunctionTwo(dc), null, WatchUi.SLIDE_IMMEDIATE);
}
}

because dc is not available in that class.

I tried multiple ways of making it somehow possible, but it wouldnt work.

Is it even possible to navigate like that or are there other good ways to do it?

Top Replies

All Replies

  • What you're trying to do wouldn't work in principle even if you had a dc, since Rez.Layouts.loadFunctionOne(dc) (for example) returns a layout (array of Drawables), not a View.

    I think you can accomplish what you want by creating View-derived classes which set their layout in onLayout():

    class LoadFunctionOneView extends WatchUi.View {
        function initialize() {
            View.initialize();
        }
        function onLayout(dc as Dc) as Void {
            setLayout(Rez.Layouts.loadFunctionOne(dc));
        }
    }
    
    class LoadFunctionTwoView extends WatchUi.View {
        function initialize() {
            View.initialize();
        }
        function onLayout(dc as Dc) as Void {
            setLayout(Rez.Layouts.loadFunctionTwo(dc));
        }
    }
    
    // ...
    // menu input delegate:
        function onMenuItem(item as Symbol) as Void {
            if (item == :item_1) {
                switchToView(new LoadFunctionOneView(), null, WatchUi.SLIDE_IMMEDIATE);
            }
            //...
        }

  • So you want to display a menu, in which the 2 options would cause the menu to be closed and then the next thing would be displayed in a way determined by which choice the user choose? Am I right?

    First of all in onMenuItem you could just set some (global) variable where you store the choice, and then "somehow" from another code do the layout switch "just a little after the menu closed".

    Secondly, maybe by not using layouts but direct calls to DC you could even do this without actually switching layout. In this scenario your "only layout's" onUpdate would draw different things to different locations depending on the same variable that you could change in onMenuItem.