Android Question Problem with dynamically adjust the height of xCustomListView items

Timm Sodtalbers

Member
Licensed User
Longtime User
Hi!
I use the MeasureMultilineTextHeight function by Alexander Stolte to dynamically adjust the height of CLV items.
This works, but adjusting the height of labels within the CLV items has no effect.
B4X:
Sub BuildCLV
    For i = 0 To comments.Size - 1
        Dim k As Map = comments.Get( i )
        CommentsCLV.Add( CreateListItem( k ), k )
    Next
End Sub

Sub CreateListItem( k As Map ) As Panel

    Dim p As B4XView = xui.CreatePanel( "" )

    p.SetLayoutAnimated( 0, 0, 0, CommentsCLV.AsView.Width, 50dip )
    p.LoadLayout( "comment" )
    
    LabelComment.Text = k.Get( "text" )

    Dim nHeight As Double = MeasureMultilineTextHeight( LabelComment )

    p.Height = nHeight + 4dip      ' works
    LabelComment.Height = nHeight  ' this has no effect (neither does SetLayoutAnimated)

    Return p

End Sub
Does anyone have an idea?
 

PaulMeuris

Well-Known Member
Licensed User
This code snippet is used by Alexander for B4A:
B4X:
    Dim su As StringUtils
    Return su.MeasureMultilineTextHeight(xLabel,xLabel.Text)
Notice that there are 2 arguments for the function: the label and the label text...
The StringUtils is a internal library in B4A.
 
Upvote 0

Timm Sodtalbers

Member
Licensed User
Longtime User
I use this in order to have it working for B4i, too:
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
Is the text long enough and not empty?
B4X:
LabelComment.Text = k.Get( "text" )
The subroutine from Alexander works just fine (tested in B4A).
Add a log line to see the contents of the text.
 
Upvote 0

Timm Sodtalbers

Member
Licensed User
Longtime User
Measuring the height is not the problem, it works very well.
I want to dynamically adjust the height of the text label in the CLV items so that the text is fully displayed.
This does not work:
B4X:
    LabelComment.Height = nHeight
The height of LabelComment does not change although nHeight has the right value.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Measuring the height is not the problem, it works very well.
I want to dynamically adjust the height of the text label in the CLV items so that the text is fully displayed.
This does not work:
B4X:
    LabelComment.Height = nHeight
The height of LabelComment does not change although nHeight has the right value.
?
set the new size

xCustomListView items

B4X:
CommentsCLV.ResizeItem(..)
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
I want to dynamically adjust the height of the text label in the CLV items so that the text is fully displayed.
How do you plan on doing that? Where is the code to change the comment label of an item?
Do the items have different heights after they are created?
BTW the suggestion from @TILogistic works fine after you set the label height (in the subroutine to change the label).
 
Upvote 0

Timm Sodtalbers

Member
Licensed User
Longtime User
How do you plan on doing that? Where is the code to change the comment label of an item?
You will find the code in my first message.
Do the items have different heights after they are created?
Yes, they have.

This is how it looks now:

clv.png


The height of the label is not adjusted to the clv item height.
 
Upvote 0

IdasI4A

Active Member
Licensed User
Longtime User
Me, I do it like this.
B4X:
    Dim Alto, AltoPanel As Int
    Dim Su As StringUtils
    
    Dim T0,T As String
    T0="Ejemplo de texto que crece. "
    T=T0
    CLV.Clear
    For i=1 To 10
        Dim P As B4XView=xui.CreatePanel("")
        p.SetLayoutAnimated( 0, 0, 0, CLV.AsView.Width, 50dip )
        P.LoadLayout("lyElemento")
        
        Dim Lbl1 As B4XView=P.GetView(0)
        Lbl1.Text="Elemento " & i
        Dim lbl2 As B4XView=P.GetView(1)
        lbl2.Text=T
        T=t & T0
        Alto=Su.MeasureMultilineTextHeight(lbl2,lbl2.Text)
        lbl2.Height=Alto
        AltoPanel=lbl2.Top+Alto+2dip
        
        p.SetLayoutAnimated( 0, 0, 0, CLV.AsView.Width, AltoPanel )
        CLV.Add(P,CLV.Size)
    Next

And I get: (lyElemento is a layout with two labels)
Captura de pantalla 2025-05-21 091110.jpg
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
Did you check the single line property of the label in the layout?
1747812418070.png

If you did then that is wrong!
If you want more help then you should post a project (with the layouts) that shows the problem like @klaus asked you to do!
 
Upvote 0

Timm Sodtalbers

Member
Licensed User
Longtime User
I just built a sample project with B4A and realized that the problem does not exist on Android.
I had tested everything with B4i and had assumed that it would not work with B4A either.
So it's probably a B4i problem and I'm in the wrong forum. Sorry and thanks for your support!
 
Upvote 0
Top