B4A Library [Class] MutableMenu - alter menu at runtime

I had a problem the other day when I needed to alter the text on my Activity menu based on the state of the application (it was for a screen lock so I need to say "Lock Screen" or "Unlock Screen" based on the state).

I couldn't find an easy way to do this but I did come across some code in the thread below that resets the menu using reflection;

http://www.basic4ppc.com/forum/basi...cript-device-basic-programming.html#post99468

So I've extended this to a class that allows you to make changes to the menu at runtime.

Currently it only supports basic menu items (not bitmaps).

You can;

1) Add menu items to the bottom of the menu
2) Add menu items at a specific index
3) Remove menu items
4) Update the text of menu items

Class and demo app attached. It requires the Reflection library in order to operate.

Hope someone finds this useful.
 

Attachments

  • MutableMenu.zip
    6.8 KB · Views: 486

derez

Expert
Licensed User
Thanks tchart, it is great !
While using it in an application I wanted to add menu items with text which is defined in the application, so I have changed the way the class works with the map. The key for the items is now the eventname, not the title. This way I can delete a menu without having to remember its exact title.
 

Attachments

  • MutableMenu_1.zip
    757 bytes · Views: 125

techknight

Well-Known Member
Licensed User
Can we update this to allow Icons/menu in the top title/action bar as well? Equivalent to AddMenuItem3 in the Core library.
 

JCO

Active Member
Licensed User
Tchart,
Many thanks, it's saved me a few headaches.
For my project, I needed a bit of extra functionality, like UpdateMenuAt and a couple other minor additions. I upload it here for anyone interested..
 

Attachments

  • MutableMenu_v1.1.zip
    870 bytes · Views: 140
Top