Android Question CustomListView panel height

Almora

Well-Known Member
Licensed User
Longtime User
hi.
B4X:
...........

        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 280dip)
         CLV1.Add(p, cd)
       
    ........
   
    Sub CLV1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 10
    For i = Max(0, FirstIndex - ExtraSize) To Min(LastIndex + ExtraSize, CLV1.Size - 1)
        Dim p As B4XView = CLV1.GetPanel(i)
        If p.NumberOfViews = 0 Then
            Dim cd As CardData = CLV1.GetValue(i)
            '**************** this code is similar to the code in CreateItem from the original example
            p.LoadLayout("Card11")
            lblTitle.Text = cd.Title
'            lblContent.Text = cd.Content
'            Log(cd.content)
            Label1.Text=cd.date
       
            Dim htm As Html
            Dim su As StringUtils
            lblContent.Text = htm.FromHtml(cd.Content)
            lblContent.Height=su.MeasureMultilineTextHeight(lblContent,lblContent.Text)
           
            ContentHolderPanel.Height=lblContent.Top+lblContent.Height+5dip

        End If
    Next
End Sub


i am using this code. everything works fine but long texts are not visible in the panel.

what should I do. thanks
 

Attachments

  • Screenshot_1643132490.png
    Screenshot_1643132490.png
    6 KB · Views: 447
Last edited:
hi.
B4X:
...........

        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 280dip)
         CLV1.Add(p, cd)
      
    ........
  
    Sub CLV1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 10
    For i = Max(0, FirstIndex - ExtraSize) To Min(LastIndex + ExtraSize, CLV1.Size - 1)
        Dim p As B4XView = CLV1.GetPanel(i)
        If p.NumberOfViews = 0 Then
            Dim cd As CardData = CLV1.GetValue(i)
            '**************** this code is similar to the code in CreateItem from the original example
            p.LoadLayout("Card11")
            lblTitle.Text = cd.Title
'            lblContent.Text = cd.Content
'            Log(cd.content)
            Label1.Text=cd.date
      
            Dim htm As Html
            Dim su As StringUtils
            lblContent.Text = htm.FromHtml(cd.Content)
            lblContent.Height=su.MeasureMultilineTextHeight(lblContent,lblContent.Text)
          
            ContentHolderPanel.Height=lblContent.Top+lblContent.Height+5dip

        End If
    Next
End Sub


i am using this code. everything works fine but long texts are not visible in the panel.

what should I do. thanks




1) open the item designer that goes inside the clv and get its height.

2) remove the AutoScaleAll line in the clv item designer.

3) change the 280dip by the height of your panel in the designer.

B4X:
        p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 280dip)
 
Upvote 0
I think you need to set height of panel namely p.

p.height = su.MeasureMultilineTextHeight(lblContent,lblContent.Text) + 60dip 'this will be additional space added into height for better visibility...
 
Upvote 0
To update clv item size,
use clv.ResizeItem to set the new size

B4X:
...........

        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, 280dip)
         CLV1.Add(p, cd)
      
    ........
  
    Sub CLV1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 10
    For i = Max(0, FirstIndex - ExtraSize) To Min(LastIndex + ExtraSize, CLV1.Size - 1)
        Dim p As B4XView = CLV1.GetPanel(i)
        If p.NumberOfViews = 0 Then
            Dim cd As CardData = CLV1.GetValue(i)
            '**************** this code is similar to the code in CreateItem from the original example
            p.LoadLayout("Card11")
            lblTitle.Text = cd.Title
'            lblContent.Text = cd.Content
'            Log(cd.content)
            Label1.Text=cd.date
      
            Dim htm As Html
            Dim su As StringUtils
            lblContent.Text = htm.FromHtml(cd.Content)
            lblContent.Height=su.MeasureMultilineTextHeight(lblContent,lblContent.Text)
          
            ContentHolderPanel.Height=lblContent.Top+lblContent.Height+5dip

           'add new line
           CLV1.ResizeItem(i,ContentHolderPanel.Height+20dip)

        End If
    Next
End Sub
 
Last edited:
Upvote 0
Back
Top