Android Question Expand a Label in CustomListView

Smee

Well-Known Member
Licensed User
Longtime User
Hi All

I have read everything I can on the forums including this link https://www.b4x.com/android/forum/t...matically-set-label-height.77849/#post-493054
but i am unable to find anything that works. I have actually tried to increase the size (Height) of the panel manually but it does not work either.

I have a clv with an image and 2 labels. They all display fine when anything is added but I cannot get the labels to increase their size automatically. Sometimes the label will have 2 lines of text and sometimes 4.
The code has been taken from the example and is

B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
      Activity.AddView(p, 0, 0, Width, Height)
    p.LoadLayout("CellItem")
    p.RemoveView
    Label1.Text = Text
    lblMessage.Text=msgTitle & CRLF & msgBody
'    clvMessage.AddTextItem(msgTitle & CRLF & msgBody,"")
    If NextRecord Mod 2 = 0 Then
            lblMessage.Color=Colors.Blue
            Label1.Color=Colors.Cyan
    Else
            lblMessage.Color=Colors.White
            Label1.Color=Colors.White
    End If
'    If NextRecord=23 Then Log(lblMessage & msgBody)
    iv1.SetBackgroundImage(bmpName)
    Return p
End Sub

I have tried .clvMessage.AddTextItem but that just puts a text label on the panel without the other views.
Can anyone point me in the direction of a working example to fix this. Also I do not understand the logic behind adding the panel (p) and then removing it. I would have thought that all the views on the panel would be removed too. I am obviously missing something here.
Appreciate any help with this
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
In the stubLabel you calculate the label height with the whole CustomListView width.
You are correct. It is a mistake. I should have subtract 140dip from the total width:

SS-2017-06-07_15.08.39.png


B4X:
p.AddView(stubLabel, 0, 0, Width - 140dip, 0)

The benefit of getting the size correctly before loading the layout is that it is simpler to make changes and add more elements with the visual designer.
 
Upvote 0
Top