iOS Question [SOLVED] Customlistview and sizetofit

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello,

I try to port my project from b4a to b4i but I encounter too many difficulties.

I am confused about: Handle Resize Event - SizeToFit - AutoScaleAll

I use a ViewPager where inside i load a listview per page. Each listview (PCLV + CLVSwipe) has it's own item's layout where in b4a i measured the height by creating dummy labels and loading texts (same as layout's labels):
B4X:
            cs.Initialize.Font(Font.DEFAULT_BOLD).Append($"${w.duration}' ${typetxt}${CRLF}${CRLF}"$).Pop.Append(w.workout).PopAll
            lblWorkoutTextDummy.AttributedText = cs
            lblWorkoutTextDummy.SizeToFit
            pnlWorkoutDummy.Height=lblWorkoutTextDummy.Top + lblWorkoutTextDummy.Height+pnlButtonsDummy.Height + 40
   
     
            Log(pnlWorkoutDummy.Height)
             
            PCLVworkout.AddItem(pnlWorkoutDummy.Height,xui.Color_Transparent,workoutSwipe.CreateItemValue(w,Null))

In clvWorkouts_VisibleRangeChanged i load data:
B4X:
Sub clvWorkouts_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
For Each i As Int In PCLVworkout.VisibleRangeChanged(FirstIndex, LastIndex)
         If i<totalRowsWorkouts Then
            Private si As SwipeItem = clvWorkouts.GetValue(i)
            Dim item As CLVItem = clvWorkouts.GetRawListItem(i)
            Dim pnl As B4XView = xui.CreatePanel("")
            item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
            Dim w As workout = si.Value
            'Create the item layout
            pnl.LoadLayout("clvWorkout")
     
            pnl.GetView(0).GetView(0).Text=w.title
   
            cs.Initialize.Font(Font.DEFAULT_BOLD).Append($"${w.duration}' ${typetxt}${CRLF}${CRLF}"$).Pop.Append(w.workout).PopAll
            pnl.GetView(0).GetView(1).As(Label).AttributedText=cs
'            misc.setLblWrapContent(pnl.GetView(0).GetView(1).As(Label),2)
            pnl.GetView(0).GetView(1).As(Label).SizeToFit
            pnl.GetView(0).Height=pnl.GetView(0).GetView(1).Top + pnl.GetView(0).GetView(1).Height+pnl.GetView(0).GetView(3).Height + 40
            pnl.GetView(0).GetView(2).Top = pnl.GetView(0).GetView(1).top + pnl.GetView(0).GetView(1).Height
          
            MediaManager.TrimMediaCache
        End If
    If LastIndex=clvWorkouts.Size-10 Then
        Log(clvWorkouts.Size)
        If (DateTime.Now > lastAddItemsTime + DateTime.TicksPerSecond) And (totalRowsWorkouts+totalRowsComments>clvWorkouts.Size) Then
            lastAddItemsTime = DateTime.Now
            getComments(clvWorkouts.Size-1,DateTime.Date(datePickerWorkouts.SelectedDate))
        End If
    End If
 
End Sub

The result is this:

1.png
3.png



The first two loaded workouts are pretty well measured but the third one has abnormal height.

If pull to refresh current workouts then every height is abnormal:

2.png


Mainpage layout (ViewPager): Handle Resize is checked and AutoscaleAll
Workouts layout (CLV): Handle Resize is checked and AutoscaleAll is off
clvWorkouts layout (item layout):Handle Resize unchecked and AutoscaleAll is off

At first load, item's height:
B4X:
360.5
244
528

after pull to refresh:
B4X:
427.5
277
578

I have searched every post containing SizeToFit, Handle Resize Event, AutoScaleAll with no luck.
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
And I do the following in every IOS app in the B4XPage_Created event:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("frm_main")
#If B4I   
wait for B4XPage_Resize (Width As Int, Height As Int)
#End If

...the rest of the code

Because the B4XPage_Resize event is triggered when the app is started and it only makes sense to fill the lists etc. afterwards.
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
And I do the following in every IOS app in the B4XPage_Created event:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("frm_main")
#If B4I  
wait for B4XPage_Resize (Width As Int, Height As Int)
#End If

...the rest of the code

Because the B4XPage_Resize event is triggered when the app is started and it only makes sense to fill the lists etc. afterwards.

Goomorning Alex,

Thank you for your response. I tried it but with no luck.

May i ask you, in b4i, if you fetch a text what procedure do you follow in order to set the correct height for the item in a pclv.

Until now, in b4a i created dummy labels(not visible) same as items label and i calculated the height (with StringUtils) in order to put the item in PCLV with the correct height.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
if you fetch a text what procedure do you follow in order to set the correct height for the item in a pclv.

Until now, in b4a i created dummy labels(not visible) same as items label and i calculated the height (with StringUtils) in order to put the item in PCLV with the correct height.
This is not possible otherwise, because you can only determine the height of the text if the function knows what the font size is and the maximum width
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
If someone encounters same behaviour, you can fix it simple by setting this in every item's label:
B4X:
lblWorkoutTextDummy.Width = Root.Width
or whatever width you need.

But firstly I followed this. I don't know if this helped, but everything working fine now.
 
Upvote 0
Top