ProgressDialogPlus – Native Android ProgressDialog Wrapper (Spinner + Horizontal)
Hi everyone

because i needed the ability to update the text inside the B4A ProgressDialog without flickering (wich isnt possible), ive created a lightweight yet powerful wrapper for the native Android ProgressDialog using JavaObject wich supports the standard Spinner and the Progressbar..
Features
- Native Android look & feel (android.app.ProgressDialog)
- No flickering while updating
- Spinner for indefinite progress (default)
- Horizontal style for percentage/progress tasks
- Dynamic control: SetMessage, SetProgress, SetMax, SetTitle, Dismiss, Cancel
- Cancelable or modal
- Works great in loops, background tasks, downloads, timeouts etc.
Function Overview
Initialize
Initializes the class context. Must be called before use.Show(Message As String, Cancelable As Boolean, Title As String, Style As String)
Displays the dialog.- Message: Text displayed in the dialog.
- Cancelable: Allows user to cancel by pressing Back.
- Title: Optional title for the dialog window.
- Style: "SPINNER" (indeterminate) or "HORIZONTAL" (with progress bar).
SetMessage(Message As String)
Updates the message text dynamically.SetTitle(Title As String)
Updates the dialog title.SetProgress(Value As Int)
Sets current progress value (only works in "HORIZONTAL" style).SetMax(Max As Int)
Sets the maximum value for the progress bar (only for "HORIZONTAL").Dismiss
Closes the dialog gracefully.Cancel
Force-cancels the dialog (equivalent to pressing back).IsShowing As Boolean
Returns True if the dialog is currently visible.
Example Usage
1. Simple Spinner Dialog
B4X:
Dim pdp As ProgressDialogPlus
pdp.Initialize
pdp.Show("Please wait...", False, "Loading", "SPINNER")
Sleep(3000) ' Simulated task
pdp.Dismiss
2. Horizontal Progress (0–100%)
B4X:
Dim pd As ProgressDialogPlus
pd.Initialize
pd.Show("Processing...", False, "Progress", "HORIZONTAL")
pd.SetMax(10)
For i = 1 To 10
pd.SetProgress(i)
pd.SetMessage("Step " & i & "/10")
Sleep(500)
Next
pd.Dismiss
3. Confirm Loop with Timeout (Horizontal + MsgBox)
B4X:
Dim maxTries As Int = 10
Dim pdp As ProgressDialogPlus
pdp.Initialize
pdp.Show("Waiting for condition...", False, "Checking", "HORIZONTAL")
pdp.SetMax(maxTries)
Dim success As Boolean = False
For i = 1 To maxTries
' Simulate check
success = (Rnd(0, 10) = 3)
pdp.SetProgress(i)
pdp.SetMessage("Attempt " & i & "/" & maxTries)
If success Then Exit
Sleep(500)
Next
pdp.Dismiss
If success Then
ToastMessageShow("Confirmed!", False)
Else
Dim res As Int = Msgbox2("Condition not confirmed. Proceed anyway?", "Timeout", "Yes", "Cancel", "", Null)
If res = DialogResponse.POSITIVE Then
ToastMessageShow("Proceeding anyway.", False)
Else
ToastMessageShow("Cancelled.", False)
End If
End If
Attachments
Last edited: