Android Question How I can resize the cell in CustomListView?

asales

Expert
Licensed User
Longtime User
If I use AddTextItem function, the height of the panel in customlistview is change automatically.

But If I create a custom panel, I don't know how to resize the height, when the text is large.

I saw the ResizeItem method, but I don't know how to use it in the code.

My example (using the example of customlistview) is in attached.

Thanks in advance for any tip.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")

    Dim lst As List
    lst.Initialize
    lst.Add("Lorem ipsum dolor sit amet.")
    lst.Add("CLorem ipsum dolor sit amet, consectetur adipiscing elit.")
    lst.Add("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce a cursus nisi, eget pretium leo.")
    lst.Add("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce a cursus nisi, eget pretium leo. Mauris eget rhoncus orci.")
    lst.Add("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce a cursus nisi, eget pretium leo. Mauris eget rhoncus orci. Nullam sit amet vehicula urna. Integer non mauris dignissim, aliquet nulla sit amet.")
    lst.Add("Lorem ipsum dolor sit amet.")
  
    For i = 1 To 6
        clv2.Add(CreateListItem(lst.Get(i), clv2.AsView.Width, 50dip), i)
    Next
End Sub

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim lb As Label
    lb.Initialize("")
    lb.Visible = False
    lb.Text = Text
    lb.TextSize = 20
    Activity.AddView(lb, 0, 0, Width, 50dip)
    intH = su.MeasureMultilineTextHeight(lb, lb.Text)
    Log(intH)
    Height =  intH
  
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0, 0, Width, Height)
    p.LoadLayout("cellitem")
    Label1.Text = Text
    Return p
End Sub

xclv1.jpg
 

Attachments

  • xclv_example1.zip
    14.3 KB · Views: 187
Last edited:
Top