Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Progress unit in ProgressDialog

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.

like image 948
hpique Avatar asked Aug 16 '10 09:08

hpique


People also ask

What is progress dialog in Android?

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.

Is ProgressDialog deprecated?

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.

Which dialog box is used to display the progress of the work?

Progress bars are used to show progress of a task.

How do you set progress dialog in Kotlin?

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.


1 Answers

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).

like image 163
hpique Avatar answered Oct 29 '22 08:10

hpique