Android Question xCustomListView dynamically adjust for content

bdw_nz

New Member
Hello,
I was looking at the example Erel did https://www.b4x.com/android/forum/threads/cards-list-with-customlistview.87720/#content

However on my phone as mentioned lblContent of Card1.bal does not increase the size based on its contents.

Is there an easy way to get the size and increase the panel height ?

The above is one example but in my user case I was thinking of having a dynamically size B4XTable which may have varying rows.

Would that size and adjust the panel ?

Apologise if the answers is obvious but pretty new to B4X
 

Andrew (Digitwell)

Well-Known Member
Licensed User
you can use the code from this forum post as a basis for resizing a label based on contents


The key is the MeasureMultiTextHeight function

B4X:
Public Sub MeasureMultiTextHeight(lbl As Label, width As Int, text As Object) As Int
    #if b4a
    Private su As StringUtils
    Return su.MeasureMultilineTextHeight(lbl, text)
    #else if b4i
    Dim plbl As Label
    plbl.Initialize("")
    plbl.Width = width
    plbl.Multiline = True
    XUIViewsUtils.SetTextOrCSBuilderToLabel(plbl,text)
    plbl.SizeToFit   
    Return plbl.Height
    #End If
    
End Sub
 
Upvote 0
Top