### Menu Items Tutorial

The Visual Designer Menu Items Tutorial can be found:
http://www.b4x.com/android/forum/threads/designer-menu-items.56602/#content
Example Context Menu
This example defines a Context Menu to a Button
Visual Designer Context Menu
In the Visual Designer define for the Button, the Context Menu as JSON String.
[
{Text:"Add", Tag:"mnuAdd", EventName: "mnuAdd"},
{Text:"Edit", Tag:"mnuEdit", EventName: "mnuEdit"},
{Text:"Delete", Tag:"mnuDelete", EventName: "mnuDelete"},
"-",
{Text:"Copy&Open Link", Tag:"mnuCopyOpenLink", EventName: "mnuCopyOpenLink", Selected: False},
"-",
{Text:"About", Tag:"mnuAbout", EventName: "mnuAbout"}
]
Notes:
• Seperators are defined by "-"
• CheckMenuItems are defined by setting Selected: True | False
• The Tag is Mandatory as used in the Code to identify the MenuItem
• The EventName is Mandatory as used in the Code to Action the Menu
Define global Map holding the MenuItems
`Sub Process_Globals
...
Private MenuItems As Map
...
End Sub`
Init the global Map in AppStart
'Menuitems Map = Context Menu assigned to Button Tools
MenuItems.Initialize
'Populate the ContextMenuItems Map from the Button Tools
CollectMenuItems(MenuItems, btnTools.ContextMenu.MenuItems)
Create the Sub CollectMenuItems
'Collate the Menu Items in the global Map MenuItems
`Private Sub CollectMenuItems(Menus As Map, Items As List)
For Each mi As MenuItem In Items
If mi.Tag <> Null And mi.Tag <> "" Then Menus.Put(mi.Tag, mi)
If mi Is Menu Then
Dim mn As Menu = mi
CollectMenuItems(Menus, mn.MenuItems)
End If
Next
End Sub`
Define the Menu Actions
As an example for JSON String {Text:"About", Tag:"mnuAbout", EventName: "mnuAbout"}
'Show the about dialog
`Sub mnuAbout_Action
Log("About this application.")
End Sub`
Etc... asdefined in the JSON string.
Example using Selected
To set the state get the MenuItem first to then read the state as set in a settingsmap:
'Check if to use copy & open link
Dim mi As CheckMenuItem = MenuItems.Get("mnuCopyOpenLink")
mi.Selected = SettingsMap.Get("copyopenlink")
The settingsmap reads like copyopenlink=true
To save use the other way around:
Dim mi As CheckMenuItem = MenuItems.Get("mnuCopyOpenLink")
SettingsMap.Put("copyopenlink", mi.Selected)

Changed: , Category: Visual Designer, File: T6C276M2046.htm, ID: 2046