Android Question xCustomListView - method AsView returns to B4XView not initialized

Roberto P.

Well-Known Member
Licensed User
Longtime User
why does the XCustomView library return an uninitialized B4XView object?
How to get around?

I would like to add a custom list view via code, as I have always done.

B4X:
m_clvInterventi.Initialize(Me, "lvInterventi")
        
        Activity.AddView(m_clvInterventi.AsView, 0dip, m_HeightToolbar, 100%x, 100%y - m_HeightToolbar )

thank in advance
 

DonManfred

Expert
Licensed User
Longtime User
The correct way to implement xCLV is to load it with a Designerlayout.

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private m_clvInterventi As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("LayoutCLV")

End Sub


Or, if you strict want to add it by code (but STILL you NEED to load it with a Layout)

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private m_clvInterventi As CustomListView
    Private xui As XUI
    Private m_HeightToolbar As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    m_HeightToolbar = 50dip
    'Do not forget to load the layout file created with the visual designer. For example:
    Dim pnl As B4XView = xui.CreatePanel("Panel")
    pnl.SetLayoutAnimated(0,0dip, m_HeightToolbar, 100%x, 100%y - m_HeightToolbar)
    pnl.LoadLayout("LayoutCLV")
    Activity.AddView(pnl, 0dip, m_HeightToolbar, 100%x, 100%y - m_HeightToolbar )

End Sub
 

Attachments

  • xclv.zip
    8.5 KB · Views: 118
Last edited:
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
With the method explained by @DonManfred the XCLV can be added as a Single View, just contained into a panel.
In this way you should have the freedom to manage everything else in your app as you desire.
 
Upvote 0
Top