Android Question Cross platform code with B4XView

mcorbeel

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

sorex

Expert
Licensed User
Longtime 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

B4X:
#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.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Or pass a list which contains references to all 1000 Objects you want to pass.
There is no limit except the available memory
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
Yes... but when I declare a label in the class the initialize method for the label is missing.
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
Okay, I can do this:

B4X:
    Dim test As Label
    test.Initialize("test")

But it says "Activity context is required"... so how can I initialize the label outside the activity?
 
Upvote 0

mcorbeel

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

mcorbeel

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

mcorbeel

Active Member
Licensed User
Longtime User
Please ignore last message.
It suddenly worked, don't know why it didn't first, or did now...
 
Upvote 0

sorex

Expert
Licensed User
Longtime 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.
 
Upvote 0
Top