Last Updated:

Dialogues in Android | ProgressDialog example

In this tutorial we will create and also look at the role in . ProgressDialogProgressBarProgressDialog

Dialogues in Android. ProgressDialog

ProgressDialog is a widget extension (more about AlertDialog).
in Android, it is a dialog box with the progress (progress) of performing a task. Sam is very similar to except what is displayed in the dialog box. To create , you need the following line of code:
AlertDialogProgressDialogProgressDialogProgressBarProgressDialog

 

Difference Between ProgressDialog and ProgressBar

  • ProgressBar is a regular one (like Button, ImageView and others) and can be used in the layout to show the progress of some task. In addition, it does not prevent the user from interacting with other parts of the application.View
  • ProgressDialog is a dialog with a built-in . It is also used to show the progress of a task, but blocks the user from accessing other elements of the screen and requires waiting for the task to be completed.ProgressBar

Methods for working with the ProgressDialog dialog

  • The method is used to display a message to the user. It often writes something like "Loading is underway...".setMessage()
  • The method is used to set the header in the dialog.setTitle()
  • Use this method to specify a horizontal progress bar in the dialog box.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL)
  • The method is used to demonstrate to the user the progress of a task in the form of a rotating indicator.setProgressStyle(ProgressDialog.STYLE_SPINNER)
  • The method is used to set the maximum progress value.setMax()
  • The method returns the maximum progress value.getMax()
  • The method is used to obtain the current value of progress in numbers.getProgress()
  • The static method is used to display the dialog on the screen.show(Context context, CharSequence title, CharSequence message)ProgressDialog
  • The method increments the indicator by the value passed as a parameter.incrementProgressBy(int diff)diff

ProgressDialog example

Below we will consider a small example of working with a dialogue.ProgressDialog

Our XML layout:

Listing of the MainActivity class:

Our application used Handler, a mechanism that allows us to process a queue of messages. We can send, receive messages, set the intervals for receiving these messages to ourselves. We will deal with this mechanism in detail in the following lessons, but for now it is enough that it allows you to update the indicator not in its flow.

The result of the application using ProgressDialog.