Android Question [B4X] Create Items for CustomListView in a class

Cadenzo

Active Member
Licensed User
Longtime User
Hi, I have a cross platform project (B4i and B4A) with shared classes an it is really only a small part of code, that cannot be shared, because of the special B4A Activity (Process_Globals / Globals). So my question, is there a way to fill also CustomListView items in a shared module or class? The problem is, that I need the views (like label "lblItemInfo"), which are in B4A destroyed when the Activity is destroyed.
B4X:
Sub ShowBookItems
    Dim li As List = Main.cG.GetBookItems
    clvBook.Clear 'CustomListView
    For Each t As BookItemType In li
        clvBook.Add(CreateBookItem(t), t)
    Next
End Sub

Sub CreateBookItem(t As BookItemType) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 100%x, 90dip)
    p.LoadLayout("viewItmBook")
    lblItemInfo.Text = t.nr
    Return p
End Sub
 

Cadenzo

Active Member
Licensed User
Longtime User
When I put the Sub CreateBookItem from Activity Module to Class, I need to define the Label lblItemInfo also in the class, right?
But then I get "Cannot access activity object from sub Process_Globals."
(The class is a B4i/B4A shared global class, once defined in Main)
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
You should put it in the Globals sub in B4A.
My shared Class ("Main.cG") is a global class for all data relevant things (SQL, maps, lists, algorithms) that is only initialized once at app start. It should be alive all the time with access from everywhere in the app. I cannot initialize it in the Globals sub in B4A.

But I guess, a second global class with UI/view relevant things, that can be initialized, if needed, in every page / activity should work. Thanks!
 
Upvote 0
Top