Original Tutorial by @narek adonts
Create a standard class module (Let assume the name of the class is UIRefreshControl),
Now you can use this class to add refresh control to any CLV of any page you want. like this,
Happy Coding
Create a standard class module (Let assume the name of the class is UIRefreshControl),
B4X:
Sub Class_Globals
Private CSB As CSBuilder
Private cb As Object
Private en As String
Private RefreshControl As NativeObject
End Sub
Public Sub Initialize(callback As Object, EventName As String, sv As ScrollView)
cb = callback
en=EventName
Dim no As NativeObject=Me
RefreshControl = no.RunMethod("AddRefresh:",Array(sv))
RefreshControl.SetField("attributedTitle",CSB.Initialize.Append("Pull to refresh").PopAll) 'You can add AttributedString
End Sub
Public Sub EndRefreshing
RefreshControl.RunMethod("endRefreshing",Null)
RefreshControl.SetField("attributedTitle",CSB.Initialize.Append("Pull to refresh").PopAll) 'You can add AttributedString
End Sub
Private Sub RC_Refresh(RC As Object)
RefreshControl.SetField("attributedTitle",CSB.Initialize.Append("Refreshing...").PopAll) 'You can add AttributedString
CallSub(cb, en&"_PullRefresh")
End Sub
#If OBJC
-(UIRefreshControl *)AddRefresh: (UIScrollView*)scrollView {
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[scrollView addSubview:refreshControl];
[refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
return refreshControl;
}
- (void)refresh:(id)sender {
UIRefreshControl *refreshControl=sender;
[self.bi raiseEvent:nil event:@"rc_refresh:" params:@[(refreshControl)]];
}
#end if
Now you can use this class to add refresh control to any CLV of any page you want. like this,
B4X:
'Code module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public MainPage As Page
Private MainPageScroll As CustomListView
Private MainRC As UIRefreshControl
End Sub
Public Sub ShowModule
MainPage.Initialize("MainPage")
Main.NavControl.ShowPage(MainPage)
MainPage.RootPanel.LoadLayout("layout1")
MainRC.Initialize(Me,"MainPageScroll",MainPageScroll.sv) 'add refresh control to CLV scrollview
End Sub
Sub MainPageScroll_PullRefresh
Sleep(3000) 'do whatever you want
MainRC.EndRefreshing
End Sub
Happy Coding
Last edited: