10-30-2008 08:00 AM
Developing with version 4.2 of the JDE
I'm confused about how the system behaves with context menus: I have a screen class that inherits from MainScreen, containing an ObjectList for which I've provided a makeContextMenu function.
I was expecting makeContextMenu to be called when the user clicks the trackball on one of the ObjectList's items, but it only seems to be invoked when the user presses the menu button. Confusingly, overriding onMenu in the screen class shows that, when the trackball is clicked, the instance parameter is INSTANCE_CONTEXT, and when the menu button is pressed it's INSTANCE_FROM_MENU_KEY, so I would have expected makeContextMenu to be called when the ObjectList has focus.
Am I missing something, or do I need to override the screen's makeMenu to get the desired behaviour (context menu only when the track-ball is clicked, full menu when the menu button is pressed)?
Solved! Go to Solution.
10-31-2008 02:32 PM
You can control this by overriding makeMenu. Please see the following for more information.
How To - Distinguish between a full menu and a primary actions menu
Article Number: DB-00565
11-11-2008 06:18 AM
Thanks for your help with this.
In the end, I made a base class for all of my main screens, extending from MainScreen, which defined two abstract methods: addContextMenuItems and addFullMenuItems for subclasses to define. In its makeMenu method, I check the value of the 'instance' parameter and only call addFullMenuItems if it's Menu.INSTANCE_DEFAULT.
This has one other benefit, in that I can set a flag in the constructor according to whether DEFAULT_MENU is specified and only call super.makeMenu in makeMenu if this has been set, because in some instances I want to define my own 'close' menu item. I always call super.makeMenu if instance == Menu.INSTANCE_CONTEXT because this adds the 'Full Menu' option.
Hopefully this is a sensible approach and will be useful to someone else!