Android's ProgressDialog allows you to set the current progress and maximum value as integers. These values are shown in the dialog like this:
3401/10023
Where the first number is the current progress, and the second number is the maximum value.
I would like to also show the unit of measurement. Something like this:
3401/10023 KB
Is this possible using ProgressDialog? If not, what do you recommend doing to give this information to the user? I'm trying to avoid reimplementing ProgressDialog just to include the unit.
Android ProgressDialog is a dialog box/dialog window which shows the progress of a task. Android Progress Dialog is almost same as ProgressBar with the exception that this is displayed as a dialog box. In order to create a ProgressDialog to display a ProgressBar we need to instantiate it like this.
ProgressDialog 's look can be replicated by placing a ProgressBar into an AlertDialog . You can still use it, but Android does not want you to use it, that is why it is deprecated.
Progress bars are used to show progress of a task.
Step by Step Implementation We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project. Navigate to the app > res > layout > activity_main. xml and add the below code to that file. Below is the code for the activity_main.
Update: setProgressNumberFormat
is part of the API since level 11.
The HEAD of the ProgressDialog
source code already includes a public function called setProgressNumberFormat
which can be used to set the unit. Unfortunately this function does not seem to be available in the latest Android version. I guess it will be included in a future update.
In the meantime, copying this implementation of ProgressDialog
is the best option. Subclassing ProgressDialog
is of no use because all of its members are private and working with view.findViewById(R.id.progress_number)
to get the TextView
directly is extremely risky, as nothing ensures that the id will be always the same (or that the TextView
will always exist).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With