Set a global time (5 seconds)
Use a 1000ms timer to update a counter.... 5.....4......3.....2......1..... REFRESH
You can for sure update the progressbar on each timer-tick.... 100%, 80%, 60%, 40% 20% REFRESH
Sub SetProgressSmoothly(PB As ProgressBar, Target As Int, Duration As Int)
Dim n As Long = DateTime.Now
Dim start As Int = PB.Progress
Do While DateTime.Now < n + Duration
PB.Progress = start + (Target - start) * (DateTime.Now - n) / Duration
Sleep(10)
Loop
PB.Progress = Target
End Sub
Usage example:
B4X:
Sub Activity_Click
SetProgressSmoothly(ProgressBar1, 100, 5000)
End Sub