Update Menu2 after popView

I currently show a menu with items, when the user clicks on some of the items, I open the next level of the menu... At some level the user reaches final settings and if the user changes them, I go back to the parent menu.

I now want to invalidate the parent menu completely after each popView (because each menu shows its value as sub label), but there is no event for that, is there? There is no onStart/onStop, no onView/onHide or similar...

Is that really not possible without handling the menu hierarchy myself and create/destroy menus accordingly?

  • Menu2 is derived from View, so it should call View.onShow() and View.onHide() appropriately.

    If you need to handle the specific case where a Menu2 is displayed after a "child" view is popped, you could:

    - implement a function in your Menu2 class which lets it know that a child has been pushed: e.g. onChildPushed()

    - pass the Menu2 instance to the corresponding input delegate on creation

    - when the input delegate pushes a child view, call onChildPushed() in your menu class which will update its internal state

    - in your menu class, implement onShow() and do what you need to do if a child was just popped (e.g. update menu item sublabels)

  • Similar to what I do now. My menus know their parents and each menu keeps track of the last clicked item => so I can simply tell the parent to update the last item after popping a menu. But I need to keep a list of menu items in each menu to know which menu belongs to which index because the index is needed for the updateItem function of the menu...

    I forget to check parent class hierarchy in the SDK documentation as I always forget that derived functions are not documented, that's why I did not see the functions from the view class.

    After implementing the above mentioned solution I think its even better than simply invalidating everything as the extra code is quite compact.

  • Yeah I think using updateItem() would likely also be better from a UX POV (it might update more quickly / smoothly).

  • But I need to keep a list of menu items in each menu to know which menu belongs to which index because the index is needed for the updateItem function of the menu...

    If you don't want to do that, you can use Menu2.findItemById() (which returns the menu index for the given ID if it exists, -1 otherwise), assuming you do have the item ID.

    Your way may be more efficient tho, depending on how you do it.

  • I was explicitly looking for this yesterday, but I did oversee it. That's of course better. Nevertheless, in the time writing a universal solution I come to the result that objects and a list of objects is a good base for the universal solution I'm writing. I want to be able to pass in a hierarchical list of objects to my class and the rest is done by the objects themself.