iOS Question Views Resize after Loading in CustomListView

Marcos Alves

Well-Known Member
Licensed User
Hello all,

Using a CLV in a B4i project I have some elements inside the items those must to be measured and adjusted to adapt the content. This question reflects on the CLV item panel height which is runtime calculated and adjusted. Some labels widths must to be adjusted also. The createPanel code is something like this:
B4X:
Private Sub createProdItem(mapProd As Map) As B4XView

    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,100%x,145dip)
    p.LoadLayout("restaurantMenuProduto")
   
    Dim lblProductName As Label = p.GetView(0)
    Dim imgProduct As ImageView = p.GetView(1)
    Dim lblProductDescrition As Label = p.GetView(2)
    Dim lblprice As Label = p.GetView(3)
    Dim lblOriginalprice As Label = p.GetView(4)
    Dim lblDash As Label = p.GetView(5)
   
    lblProductName.Text = mapProd.Get("description")
    lblProductDescrition.Text = mapProd.Get("details")
   
    Dim unitPrice As Double = mapProd.Get("unitPrice")
    lblprice.Text = "R$ " & NumberFormat2(unitPrice,1,2,2,False).Replace(".",",")
    Dim unitMinPrice As Double = mapProd.Get("unitMinPrice")
   
    Dim can As B4XCanvas
    can.Initialize(Root)
    Dim rec As B4XRect
    rec = can.MeasureText(lblprice.Text,lblprice.Font)
    lblprice.Height = rec.Height
   
    If unitPrice > 0 Then
        Dim unitOriginalPrice As Double = mapProd.Get("unitOriginalPrice")
        If unitOriginalPrice = 0 Then
            lblOriginalprice.Visible = False
            lblDash.Visible = False  
        Else
            lblprice.TextColor = Colors.Green
            lblOriginalprice.Text = "R$ " & NumberFormat2(unitOriginalPrice,0,2,2,False).Replace(".",",")
            rec = can.MeasureText(lblOriginalprice.Text.trim,lblOriginalprice.Font)
            lblDash.Width = rec.Width
            lblDash.Top = lblOriginalprice.Top + lblOriginalprice.Height / 2 - 4dip
           
        End If
    Else
        lblprice.Text = "A partir de R$ " & NumberFormat2(unitMinPrice,1,2,2,False).Replace(".",",")
        lblOriginalprice.Visible = False
        lblDash.Visible = False
    End If
       
    imgProduct.Tag = mapProd
   
    p.Height = lblprice.Top + lblprice.Height + 25dip
   
    mapProd.Put("panelType","produto")
    p.Tag = mapProd
    Return p
   
End Sub

I noticed that, if I pause the execution (F8 - step by step), I can see on the screen the views being correctly modified by the code but, after all code to run, something that isn't showed in logs resizes the entire screen screen (correctly, because the CLV panels are adjusted to the correct width), but rolls back the runtime adjusts of the views.
Doesn't matter what height or width I set for the labels inside CLV panels, at the end it always returns to the original size configured in the layout.

What is happening? Is there something wrong in the code?

Please help - anybody?

Thanks !!!

PS: the entire project uses B4XPages
 

Marcos Alves

Well-Known Member
Licensed User
Make sure that the "handle resize event" option is unchecked in the item's layout file.
Thanks @Erel . It's checked, I'll uncheck and test! I was suspecting of this configuration but didn't found any documentation about it. Where can I found a documentation about this resource?
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Make sure that the "handle resize event" option is unchecked in the item's layout file.
Update -> thanks @Erel !!! Worked .
Suggestion: could be interesting in CustomListView orientations/tutorial to register this detail for B4i . I spent some time trying to figure out why the views sizing commands weren't doing effect when loading CLV panels...
 
Upvote 0
Top