Displaying Progress Dialogs

You may want to indicate progress in a dialog window, as opposed to adding a ProgressBar control to the layout of an existing screen. You can use the special Dialog class called ProgressDialog for this purpose. For example, you can use ProgressDialog windows (see Figure 15.4) in the Been There, Done That! application to inform the user that data is being downloaded and parsed before displaying the appropriate screen of the application.

FIGURE 15.4

Informing the user that trivia questions are being downloaded.

^aftiPa 9-15 PM I

^aftiPa 9-15 PM I

Here is the code needed to programmatically create and display the ProgressDialog class:

ProgressDialog pleaseWaitDialog = ProgressDialog.show( QuizGameActivity.this, "Trivia Quiz",

"Downloading trivia questions...", true);

You can use the dismiss() method to dismiss pleaseWaitDialog control when you have completed any background processing:

pleaseWaitDialog.dismiss();

The pleaseWaitDialog control can be cancelled by the user if a fifth parameter is added to the show() method and set to true. In this case, we don't allow the user to cancel the dialog because we want it showing during the entire download. In the example code, which shows the final results for this hour, you'll see we do allow it to be cancelled, and you can read about it later in this hour.

Now you know how to create progress bars and display them in dialog windows using ProgressDialog control. Because the progress you want to indicate should actually be taking place asynchronously, it's time to turn our attention to background processing.

0 0

Post a comment