Android Question B4X Cross platform AddMenuItem

davemorris

Active Member
Licensed User
Longtime 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
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Cross platform code is a tool, not a target by itself.
2. There is no identical feature in iOS. You can choose to use a different solution such as B4XDrawer.
3. Another option is to use ActionSheet in B4i and the standard menu in B4A. You can always catch the events in the activity and delegate them to the cross platform class.
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime 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:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime 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
 
Upvote 0
Top