Is there a way to differientate which menu item has been pressed?

Penko

Active Member
Licensed User
Longtime User
Hi there.

I would like to use a single Event which is triggered when a button on the menu has been pressed. Unfortunately, I am unable to understand how to get the Sender.

B4X:
Sub addMenus()
   Activity.AddMenuItem("About","menu")
Activity.AddMenuItem("Next One","menu")
Activity.AddMenuItem("Third","menu")
End Sub

Sub menu_Click()
Dim a as [WHAT]
a = Sender
'  if I manage to extract the value it would be much better.

' Here I will do a Select Case of the values and Start the corresponding Activity.
End Sub

I am doing this for the sake of simplifying my code via a central method in a Code Module and I want to handle a single click event in all Activities.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
The Sender is the Menu Title text.
B4X:
Sub AddMenus
    Activity.AddMenuItem("About", "Menu")
    Activity.AddMenuItem("Next one", "Menu")
    Activity.AddMenuItem("Third", "Menu")
End Sub

Sub Menu_Click
    Dim txt As String
    
    txt = Sender
    
    Select txt
    Case "About"
    Case "Next one"
    Case "Third"
    End Select
End Sub
Best regards.
 
Upvote 0
Top