mcorbeel Active Member Licensed User Longtime User Nov 30, 2018 #1 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...
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...
S sorex Expert Licensed User Longtime User Nov 30, 2018 #2 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. Upvote 0
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.
DonManfred Expert Licensed User Longtime User Nov 30, 2018 #3 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
Or pass a list which contains references to all 1000 Objects you want to pass. There is no limit except the available memory
mcorbeel Active Member Licensed User Longtime User Nov 30, 2018 #4 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 Nov 30, 2018 #5 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? Upvote 0
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?
mcorbeel Active Member Licensed User Longtime User Nov 30, 2018 #6 Okay, solved it, thanks to Sorex's example. Thank you all !!! Upvote 0
mcorbeel Active Member Licensed User Longtime User Dec 6, 2018 #7 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
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?
S sorex Expert Licensed User Longtime User Dec 6, 2018 #8 your click event callback will be in the class. Upvote 0
mcorbeel Active Member Licensed User Longtime User Dec 7, 2018 #10 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! Upvote 0
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!
mcorbeel Active Member Licensed User Longtime User Dec 7, 2018 #11 Please ignore last message. It suddenly worked, don't know why it didn't first, or did now... Upvote 0
S sorex Expert Licensed User Longtime User Dec 8, 2018 #12 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
maybe you added the sub while the debug mode was still running? some things require a stop and re-start before they will work.
mcorbeel Active Member Licensed User Longtime User Dec 9, 2018 #13 maybe... don't know anyway, glad that it works... saves me a lot of time! Upvote 0