iOS Question xCustomListView Pull to refresh is not pullable when less item

aeric

Expert
Licensed User
Longtime User
In B4i, I try to implement Pull to Refresh by using the sample from [B4X] CLVSwipe - xCustomListView Swipe actions and pull to refresh

The sample works when the items populated with content height more than the CustomListView's height but if I have less item, I cannot pull to refresh the list.

B4X:
Sub CreateItems
    Dim cs As CSBuilder
    For i = 1 To 5 '100
        cs.Initialize.Color(Rnd(0xff000000, -1))
        If i Mod 3 = 0 Then
            cs.Append($"Important item ${i} ..."$).PopAll
            CustomListView1.AddTextItem(cs, Swipe.CreateItemValue("", Array("Delete", "Do Something Else")))
        Else If i Mod 3 = 1 Then
            cs.Append($"Very important item ${i} ..."$).PopAll
            CustomListView1.AddTextItem(cs, Swipe.CreateItemValue("", Array("Action 1", "Action 2", "Action 3")))
        Else
            cs.Append($"Nothing to see here ${i}"$).PopAll
            CustomListView1.AddTextItem(cs, Null)
        End If
    Next
End Sub

I don't have this problem with B4A.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The list must be scrollable for the pull gesture to work. You can add a "stub" item.

This code, taken from XUI Views, adds a stub item if needed:
B4X:
Public Sub InternalAddStubToCLVIfNeeded(CustomListView1 As CustomListView, Color As Int)
   If CustomListView1.Size = 0 Then Return
   Dim LastItem As CLVItem = CustomListView1.GetRawListItem(CustomListView1.Size - 1)
   If LastItem.Offset + LastItem.Panel.Height < CustomListView1.AsView.Height Then
       'add a stub item
       Dim p As B4XView = xui.CreatePanel("stub")
       p.Color = Color
       Dim Height As Int = CustomListView1.AsView.Height - LastItem.Offset - LastItem.Panel.Height - 3dip
       If xui.IsB4J Then Height = Height + 5
       p.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, Height)
       CustomListView1.Add(p, "")
       CustomListView1.sv.ScrollViewContentHeight = CustomListView1.sv.ScrollViewContentHeight - CustomListView1.DividerSize
   End If
End Sub
 
Upvote 0
Top