Android Question B4X Cross platform AddMenuItem

Discussion in 'Android Questions' started by davemorris, Aug 2, 2019.

  1. davemorris

    davemorris 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
     
  2. Erel

    Erel Administrator Staff Member Licensed 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.
     
  3. davemorris

    davemorris 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
    Code:
    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.
    Code:
    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: Aug 3, 2019
  4. Erel

    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:
    Code:
    Sub Menu_Click
      MyClass.MenuClicked(
    Sender)
    End Sub

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

    davemorris Member Licensed User

    Hi, Erel
    Thanks for the quick response - I will give it a try.

    Kind regards
    Dave
     
  6. davemorris

    davemorris 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
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Change the type of 'Parent' to Activity.
     
  8. kstainsb

    kstainsb Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice