Android Question B4X Cross platform AddMenuItem

davemorris

Active Member
Licensed User
Hi Guys
I am trying to convert a project which runs on both B4A and B4I to be cross platform. I have started with converting the B4A, but hit a query. How do I deal with AddMenuItem - I am trying to move as much code as possible to X-platform class as suggested by Erel in

https://www.b4x.com/etp.html?vimeography_gallery=1&vimeography_video=256289568

It looks to me that the AddMenuItem must remain in the Activity code along with the related event handlers.

Basically, am I missing something or is that how it is!

Kind regards
Dave
 

davemorris

Active Member
Licensed User
Hi Erel
Thanks for the response - Guess I should not have mentioned X-Platform - it has thrown you in the wrong direction (but fully agree with what you say).

This currently only relates to B4A code (not B4i).
I initialize the helper class using some like classname.initialize(Activity)

Then in the helper class initialize is declared something like
B4X:
Public Sub Initialize (parent As B4XView)
    parent.LoadLayout("fromToDisplay")
End Sub
' What I would like to is add menu options to the activity but put the code in the helper class i.e.
B4X:
Public Sub Initialize (parent As B4XView)
    parent.LoadLayout("fromToDisplay")

' Tried this by it don't work
    parent.AddMenuItem("Option description", "HandlerName")
       ' Plus some menu options
End Sub
IMPORTANT: I have to say that I am a BIG supporter of your attempts to support X-Platform - In my opinion, if you are writing any application for multiple platforms - it is a must to use B4X.

Very kind regards
Dave
 
Last edited:

Erel

Administrator
Staff member
Licensed User
You can add menu items in the class however the menu events will be raised in the activity module.

You can set the event name of all menu items to be the same (Menu for example) and then delegate the click event to the class:
B4X:
Sub Menu_Click
  MyClass.MenuClicked(Sender)
End Sub

'in the class
Public MenuClicked(Text As String)
 Log(Text)
End Sub
 

davemorris

Active Member
Licensed User
Hi, Erel
I still can't see how to add menu items from within a class (see previous posts for my failed attempt).

Kind regards
Dave
 
Top