Android Question How I can resize the cell in CustomListView?

Discussion in 'Android Questions' started by asales, May 21, 2019.

  1. asales

    asales Well-Known Member Licensed 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.

    Code:
    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, 00, Width, 50dip)
        intH = su.MeasureMultilineTextHeight(lb, lb.Text)
        
    Log(intH)
        Height =  intH
      
        
    Dim p As Panel
        p.Initialize(
    "")
        p.SetLayout(
    00, Width, Height)
        p.LoadLayout(
    "cellitem")
        Label1.Text = Text
        
    Return p
    End Sub
    xclv1.jpg
     

    Attached Files:

    Last edited: May 21, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    One simple way is to add the items with AddTextItem and then add other views:
    Code:
    CLV.AddTextItem(...)
    Dim p As B4XView = CLV.GetPanel(CLV.Size - 1)
    'add views to P
     
    jimmyF likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice