B4J Question Context Menu on Runtime

BarryW

Active Member
Licensed User
Longtime User
How to add context menu to a button on runtime. I want to add a tag to a menuitem on loop.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   Dim cm As ContextMenu
   cm.Initialize("cm")
   For i = 1 To 10
     Dim mi As MenuItem
     mi.Initialize("Item #" & i, "mi")
     cm.MenuItems.Add(mi)
   Next
   Button1.ContextMenu = cm
End Sub

Sub mi_Action
   Dim mi As MenuItem = Sender
   Log(mi.Text)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…