Android Question PCLV.AddItem(Size,Clr,Value) - how to determine Size for different devices

Mark Stuart

Well-Known Member
Licensed User
Longtime User
Hi y'all,
The app will run on different device sizes and therefore, how do I determine the Size argument in the PCLV.AddItem(Size,Clr,Value)?
The Size argument is actually the Height of the panel that is added in the PCLV.AddItem method.

When testing on 2 device sizes, the static Size value does not work, as for each device, it measures differently.

Regards,
Mark Stuart
 

Mark Stuart

Well-Known Member
Licensed User
Longtime User
Hi. Yes I know that, but how do I decide what that number is that works for all devices, as I've seen that a scpecific number doesn't work for more than one device.
If I set it for one device, it is either too short or too tall for another device.
 
Upvote 0

b4x-de

Active Member
Licensed User
Longtime User
Ok, then you might want to turn off the AutoScale in the script section of your layout files to achieve what you want to achieve?
 
Upvote 0

Mark Stuart

Well-Known Member
Licensed User
Longtime User
Will give it a try.

EDIT: Unfortunately that did not work.
I commented out AutoScaleAll on both the layouts, the CLV and the CLV detail.
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You need to re-set the panel height after the layout gets loaded...
The "screen" resolution (width and height) is only known to b4A after the Layout is loaded., or you could try something like 90%y as height value, meaning 90% of the available height, but this value may NOT be available at layout loading time
 
Upvote 0

Mark Stuart

Well-Known Member
Licensed User
Longtime User
So I tried this...
B4X:
Sub FillList(filter As String)
    clvItems.Clear
    
    Dim items As List = DBCalls.Items_GetAll(SortByField)
    If items.Size > 0 Then
        For Each item As Map In items
            Dim plu As String = item.Get("PLU")
            Dim desc As String = item.Get("Description")
            If plu.Contains(filter) Or desc.ToLowerCase.Contains(filter) Then
                PCLV.AddItem(60dip,xui.Color_White,item)
            End If
        Next
        PCLV.ShowScrollBar = True
    End If
    PCLV.Commit
    PCLV.lblHint.Font = xui.CreateDefaultBoldFont(14)
    PCLV.lblHint.TextColor = xui.Color_Black
    PCLV.pnlOverlay.Color = xui.Color_LightGray
End Sub

B4X:
Sub clvItems_VisibleRangeChanged(FirstIndex As Int, LastIndex As Int)
    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = clvItems.GetRawListItem(i)
        
        Dim pTemp As B4XView = xui.CreatePanel("")
        pTemp.SetLayoutAnimated(0,0,0,100%x,100%y)
        pTemp.LoadLayout("Item_Info")
        
        Dim p2 As Panel = pTemp.GetView(0)
        Dim pHeight As Int = p2.Height + 18dip
        pTemp.RemoveAllViews
        
        Dim pnl As B4XView = xui.CreatePanel("")
        
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, pHeight)
        pnl.LoadLayout("Item_Info")
        pnl.Height = pHeight
        
        Dim itm As Map = item.Value
        lblPLU.Text = itm.Get("PLU")
        lblDescription.Text = itm.Get("Description")
        lblPrice.Text = "$" & itm.Get("Price")
    Next
End Sub
It seems to work on a Samsung S23 Plus 6 1/2" and a Samsung SM-T380 8"
 
Upvote 0
Top