Android Question ProgressBar based on Timer

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi there.

I would like to know if it is possible to have a progressbar on my app (tablet based) where it will incremente smoothly for 5 seconds for example.

This app refresh data each 5 seconds and I would like to give a feedback to the user.

I have already a timer that ticks every 5 seconds for the update.

Any ideas?

Thank you
 

DonManfred

Expert
Licensed User
Longtime User
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
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
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
 
Upvote 0
Top