Android Question Cross platform code with B4XView

Discussion in 'Android Questions' started by mcorbeel, Nov 30, 2018.

  1. mcorbeel

    mcorbeel Member Licensed User

    I recently discovered B4XView and its possibilities to share code between platforms.
    Though this is a great improvement, I have 1 issue that I cannot solve with my knowledge of today.
    For Android I declare and initialize my controls in the activity, for iOS I do this in my page. Then I pass these controls to the cross platform class that constructs the page. I do not like using the designer, so I add/position and setup my controls by code in the shared class. This also results in much faster display.
    So far so good... But for some pages I use dozens and dozens of labels to construct a list. Is there no way I can do this in the class? Often these labels contain records from database so I cannot pass dozens or hundreds of controls to the class.
    Is there a work around for this?
    If not clear I make a sample app that will make it clear...
     
  2. sorex

    sorex Expert Licensed User

    I don't see why you can't create them in the class.

    just pass the activity or destination panel to the class and add your views to it.

    you can use this for example in the init of your main class

    Code:
    #if B4A
    Public Sub Initialize(act As Activity)
     mainactivity=act
     dirData=
    File.dirinternal
     dirAssets=
    File.dirassets
    #end if
    #if B4i
    Public Sub Initialize(act As Page)
     mainactivity=act.RootPanel
     dirData=File.DirLibrary
     dirAssets=File.DirAssets
    there's an object method aswell which Erel once showed but I couldn't get everything to work with it for some reason.
     
  3. DonManfred

    DonManfred Expert Licensed User

    Or pass a list which contains references to all 1000 Objects you want to pass.
    There is no limit except the available memory
     
  4. mcorbeel

    mcorbeel Member Licensed User

    Yes... but when I declare a label in the class the initialize method for the label is missing.
     
  5. mcorbeel

    mcorbeel Member Licensed User

    Okay, I can do this:

    Code:
    Dim test As Label
        test.Initialize(
    "test")
    But it says "Activity context is required"... so how can I initialize the label outside the activity?
     
  6. mcorbeel

    mcorbeel Member Licensed User

    Okay, solved it, thanks to Sorex's example.
    Thank you all !!!
     
  7. mcorbeel

    mcorbeel Member Licensed User

    Well, solved partially...
    If I need the click event in my activity... then how can I do this if the label is initialized in my shared class?
     
  8. sorex

    sorex Expert Licensed User

    your click event callback will be in the class.
     
  9. mcorbeel

    mcorbeel Member Licensed User

    Indeed it is!
    Thanks
     
  10. mcorbeel

    mcorbeel Member Licensed User

    But... I have a click event that works in b4a but not in b4i.
    It is in a class module that is shared, and thus is completely identical.
    I have a button called Button_Planning_List that I initialize in my class initialize sub.

    Then I have my click event in that class:
    Code:
    Sub Button_Planning_List_Click
        
    #if b4a
        
    StartActivity("Page_Planning_List")
        
    #End If
        
    #if b4i
        Dim hd As HUD
        hd.ToastMessageShow("Button_Planning_List_Click", False)
        Page_Planning_List.Show
        
    #End If
    End Sub
    In b4a it works and the activity Page_Planning_List shows.
    In b4i nothing happens...

    Any help welcome!
     
  11. mcorbeel

    mcorbeel Member Licensed User

    Please ignore last message.
    It suddenly worked, don't know why it didn't first, or did now...
     
  12. sorex

    sorex Expert Licensed User

    maybe you added the sub while the debug mode was still running?

    some things require a stop and re-start before they will work.
     
  13. mcorbeel

    mcorbeel Member Licensed User

    maybe... don't know
    anyway, glad that it works... saves me a lot of time!
     
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