Android progress bar using progressDialog


Download android date picker sample

To show progress of a task, we use progress bar. We should use progress dialog if we want the user to wait till the task complete. For example, When we are downloading or uploading something, then we should show progress dialog so that the user get to know that some process is running in the background.

Progress bar can be devided into 2 parts based on there characteristic:

Indeterminate progress bar


A progress bar can be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation without an indication of progress. This mode is used by applications when the length of the task is unknown. The indeterminate progress bar can be either a spinning wheel or a horizontal bar.

Determinate progress bar.


A progress bar can be made determinate. This mode is used by applications when the length of the task is well known.

Android Progress Dialog and Progress bar Android Progress Dialog and Progress bar

Android Progress Dialog and Progress bar Android Progress Dialog and Progress bar

Android Progress Dialog and Progress bar


Example


In this example, I've tried to show determinate as well as indeterminate progress bar using ProgressDialog and ProgressBar widget.

Step 1: Create a new project in Android Studio and name it Android progress bar.

Step 2:Open res -> drawable -> activity_main.xml and replace the code with code of activity_main.xml with the below given code.

activity_main.xml

Step 3: Open MainActivity.java and replace its code with below given code.

MainActivity.java

Step 4:Clean and run your project to see the result.

Share & Like

Tutorial topics

About ApnaTutorials.com

ApnaTutorials.com is for Java, J2ee, Html5 and android developers. All tutorials are well explained and are easy to understand. We have tested every tutorials on our developement environment before posting it in public domain.