B4A Library MLmenu menu library

An easy to use menu that can be displayed from various positions on the users screen. It can contain bitmaps along with the menu item name(s).

This is version 1.1.1. source iin B4A and test project is attached in the menusrc.zip file.

MLmenu
Author:
Jem Miller
Version: 1.11
  • MLmenu
    Events:
    • Click (Position As Int, Value As String)
    Methods:
    • IsInitialized As Boolean
      Tests whether the object has been initialized.
    • addmenuitem (Title As String, Image As BitmapWrapper) As String
      Adds an item to the menu.
      Title - title displayed in the menu.
      Image - Pass Null if there is no image to load.
    • addmenuitemat (Title As String, Image As BitmapWrapper, Position As Int) As String
      Adds an item to the menu in the specified position.
      Title - title displayed in the menu.
      Image - put Null if there is no image to load.
      Position - position in the menu.
    • closemenu As String
      Programmatically closes the menu.
    • initialize (MaxItemShow As Int, ItemHeight As Int, Parent As ActivityWrapper, Module As Object, bgColor As Int, txtColor As Int, TextSize As Float, Event As String) As String
      Initializes the ModularMenu.
      MaxItemShow - maximum number of item visible in the menu.
      HeightItem - height of each item. in DIP units.
      Parent - The Main Activity (Should always be Activity)
      Module - must be Me (with no " marks)
      bgColor - Menu color
      txtColor - Text color
      TextSize - Text size
      Event - Event name to raise on Click event (create an event with this prototype: Event_Click(Position as Int, Value as String).
    • isvisible As Boolean
      Returns True if menu is currently showing.
    • openmenu As String
      Programmatically opens the menu.
    • openmenuat (Left As Int, Top As Int) As String
      Programmatically opens the menu at a specified location.
      Left - Left edge of menu.
      Top - Top edge of menu.
    • openmenucentered - Opens the menu in the center of the screen
    • removeall As Boolean
      Removes all items from the menu.
    • removeat (Index As Int) As Boolean
      Removes the item at the specified position.
    • size As Int
      Returns the number of menu items [read only].

Versions
1.1.0 - Initial release

1.1.1 - Added OpenMenuCentered to open the menu centered in the screen. Fixed a pesky bug in the OpenMenuAt routine.


.
 

Attachments

  • menu.png
    menu.png
    238.4 KB · Views: 1,802
  • MLmenu-1.11.zip
    28.6 KB · Views: 668
  • menusrc.zip
    23.3 KB · Views: 584
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Nice... Thanx for sharing!
But i have one Question... How can i set the WIDTH of the Menu?

i have changed the menuitems in your example to

B4X:
mnu.AddMenuItem("Test bla",LoadBitmap(File.DirAssets,"configure.png"))
mnu.AddMenuItem("Test blabla",LoadBitmap(File.DirAssets, "search.png"))
mnu.AddMenuItem("Test blubber",LoadBitmap(File.DirAssets, "wand.png"))
mnu.AddMenuItem("Test blub",LoadBitmap(File.DirAssets, "exit.png"))

BUT the Menu looks something like this:

B4X:
++++++++++++++
+icon1+ Test bla  +
++++++++++++++
+icon2+Test blabl+ 
++++++++++++++
+icon3+Test blub+
++++++++++++++
+icon4+Test blub +
++++++++++++++

If i look at this example and think over the Menuitems i would use in german i would prefer a wider Menu cause german words are often longer than the english ones...

Options - Einstellungen
Quit - Beenden
submit order - Bestellung absenden

It would be great if you can insert a option to set the width for the entire menu

May i ask whether this lib is a "compiled as lib-b4a-project" or not?
If it is an java-project then it is not interesting for me but if it is an compiled b4a-project to a lib; could you give the a copy of the source of the lib to me? I have more ideas i would like to implement in it ;)
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Hi Don,

The width should adjust automatically depending upon the length of the longest line. Mine does, but I have attached the source to the first post. Play with it as you will and have fun!

--- Jem
 

scsjc

Well-Known Member
Licensed User
Longtime User
hello,
i trie your library, and have a problem, when y push the key back, the application is stoped,
i dont know if about problem with version android 4.3....

sorry from my english.
thanks
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Yes, you have to handle the back key yourself in the Activity_Keypress event like:
mnu is the MLmenu object below


B4X:
If KeyCode = KeyCodes.KEYCODE_BACK Then
  
   If mnu.IsVisible Then
   mnu.CloseMenu
   Return True
End if

End if

--- Jem
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Not sure if the library version was correct inside the zip file, so I have uploaded a known working version (same version number). If you have had problems with the menu not showing or other strange stuff, download the library again and try this version.

--- Jem
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Added OpenMenuCentered to open the menu centered in the screen. I also found and fixed a small bug in the OpenMenuAt sub that would prevent the menu from showing.

--- Jem
 

incendio

Well-Known Member
Licensed User
Longtime User
Hello,

Thanks for this library, I was using this library long time ago in previous B4A.
Now on B4A ver 7, didn't work anymore, raised an error :

java.lang.NoSuchMethodError: anywheresoftware.b4a.objects.ListViewWrapper.AddTwoLinesAndBitmap

Any hints to correct this?
Thanks in advance.
 

incendio

Well-Known Member
Licensed User
Longtime User
That's the problem, have compile source code in B4A 7 & got error :

Error pkg: /data/local/tmp/menutst.apk
Failure [INSTALL_FAILED_VERSION_DOWNGRADE]
 

Claudio Oliveira

Active Member
Licensed User
Longtime User
Looks like you're trying to install/run an older version apk file.
Try this:
Compile the library alone with B4A 7.
Copy the generated .jar and .xml files to your additional libraries folder.
Open your project and refresh your libraries references.
Compile and run your project.

I did this here with menutst, and it worked ok.
 

incendio

Well-Known Member
Licensed User
Longtime User
Looks like you're trying to install/run an older version apk file.
Try this:
Compile the library alone with B4A 7.
Copy the generated .jar and .xml files to your additional libraries folder.
Open your project and refresh your libraries references.
Compile and run your project.

I did this here with menutst, and it worked ok.
That's great. Have tried this and worked fine.

In case somebody needed, attached is a new library compiled with B4A ver 7. Only changed in version # to distinguish with the original one.
All credits goes to Jem Miller.
 

Attachments

  • MlMenu1-2.zip
    6.9 KB · Views: 285

Claudio Oliveira

Active Member
Licensed User
Longtime User
That's great. Have tried this and worked fine.

In case somebody needed, attached is a new library compiled with B4A ver 7. Only changed in version # to distinguish with the original one.
All credits goes to Jem Miller.

Nice! :)
 

Claudio Oliveira

Active Member
Licensed User
Longtime User
It is already there when compinling something to s library.
Yeah, that's right.
But in this case I've decided to compile the library in a different folder to avoid messing with the original additional libraries folder, just for test purposes...
 
Top