Better implementation is available here: https://www.b4x.com/android/forum/t...tview-swipe-actions-and-pull-to-refresh.98252
You can use this code to add a pull to refresh feature to the standard xCustomListView.
The code should be added to the activity.
Project is attached.
You can use this code to add a pull to refresh feature to the standard xCustomListView.
The code should be added to the activity.
B4X:
Sub CLV_ScrollChanged (Offset As Int)
ScrollIndex = ScrollIndex + 1
Dim MyIndex As Int = ScrollIndex
If TopPanel.Parent.IsInitialized Then
If Offset < TopPanel.Height / 3 Then
Refresh
End If
TopPanel.GetView(1).TextSize = 20 * (TopPanel.Height - Offset) / TopPanel.Height
Else If Offset = 0 And TopPanel.Parent.IsInitialized = False Then
Sleep(200)
If MyIndex = ScrollIndex Then
If TopPanel.Parent.IsInitialized = False Then
CLV.InsertAt(0, TopPanel, "")
TopPanel.GetView(1).Text = "Pull to refresh"
CLV.sv.ScrollViewOffsetY = TopPanel.Height + CLV.DividerSize
End If
End If
End If
End Sub
Private Sub StopRefresh
Refreshing = False
If TopPanel.Parent.IsInitialized Then
TopPanel.RemoveViewFromParent
CLV.RemoveAt(0)
B4XLoadingIndicator1.Hide
End If
End Sub
Private Sub Refresh
If Refreshing Then Return
Refreshing = True
B4XLoadingIndicator1.Show
TopPanel.GetView(1).Text = "Loading..."
Log("Refresh")
'refresh items...
Sleep(2000)
For i = CLV.Size - 1 To 1 Step -1
CLV.RemoveAt(i)
Next
For i = 1 To 20
CLV.AddTextItem($"Item #${Rnd(1, 1000)}"$, "")
Next
StopRefresh
End Sub
Project is attached.
Last edited: