B4J Question Changing MenuItem prompt after initialization [solved]

Didier9

Active Member
Licensed User
I would like to be able to change the prompt of a MenuItem after it has been initialized. Is it possible?
 

Didier9

Active Member
Licensed User
Thank you, a little more complicated than I was hoping for but will get the job done :)
 

Didier9

Active Member
Licensed User
I did find a simpler way. It's certainly a less general answer but it works well enough for me at the moment.
Instead of using the code as I have seen in the examples where the submenu m is declared locally in App_Start():
B4X:
Sub App_Start(...)
    ' create top level menu entry
    Dim TopMenu As Menu
    TopMenu.Initialize( "Top Menu", "" )
    mb.Menus.Add( TopMenu )
    ' Add submenu
    Dim m As MenuItem
    m.Initialize( "Sub Menu", "mSubMenu" )
    TopMenu.MenuItems.Add( m )
I declare the sub menu as a process global variable:
B4X:
Sub Process_Globals
    Private m1 as MenuItem
End Sub
Sub App_Start(...)
    ' create top level menu entry
    Dim TopMenu As Menu
    TopMenu.Initialize( "Top Menu", "" )
    mb.Menus.Add( TopMenu )
    ' Add submenu
    m1.Initialize( "Sub Menu", "mSubMenu" )
    TopMenu.MenuItems.Add( m1 )
and when I want to change the prompt anywhere in the code:
B4X:
    m1.Text = "bla bla"
 
Top