Setting menu focus from delegate

Can I set the focus of the menu in the delegate of the view containing the menu?

I have tried testing by setting a timer in the View to call menu.setFocus(1) after a small amount of time (i.e. after the menu is rendered) and it doesn't work.

Therefore, I assume that passing a reference of the menu object to the delegate and calling setFocus() from there wouldn't work either.

Is this fair to assume? Any way to actually go about this?

  • I'm pretty sure you can. I think I did it. It would be helpful if we could see the relevant code. IMHO the whole point of the delegate is to change the CURRENT view. If it's not the current then of course you won't be able to see the changes as you do them, but you might still be able to set the focus and see it when that view becomes the active view.

  • TL;DR it seems that setFocus() only works properly (in the sim and real device) when it's called before the menu is rendered. Not sure if this is a bug or intentional limitation.

    --

    I just tried this in the same way you did (after pushing the menu, set a timer which calls Menu2.setFocus()). Additionally, I added a call to setTitle().

    What I found (in the simulator):

    - if you don't use a timer, but instead call setFocus() in the same "execution context" as pushView() - i.e. in the same function, before control returns to code outside of the app, and before the menu is rendered - everything works fine (as might be expected)

    - the timer expiration value doesn't matter (I tried both 1 and 5000). Like you said, the relevant effect of using a timer is to make the code run after the menu is rendered (same as it would with a delegate)

    - you do also have to call WatchUi.requestUpdate() for any change to the menu to be reflected at all (as expected)

    - setTitle() works without problems

    - the setFocus() call *appears* not to work (the highlighted item on the screen is unchanged), but if you press UP, DOWN or START, you will see that it actually did work (in the sense that the selected item was changed)

    - I tested the same code in the menu delegate: both setTitle() and setFocus() worked as expected

    On a real device (fr955):

    - setFocus() doesn't work when called either from a timer or in the menu delegate. it does work when called before the menu is rendered

    So it seems that the intended usage of setFocus() is to set the focus *before* the menu is displayed. It doesn't really seem to work properly if you call it afterwards.

    If you really want to change the focused item programmatically, you may have to destroy the menu and re-render it (which of course might suck from a UX POV). Or you could file a bug report and see if this is intended behaviour or not.