7

Dialogs @ Android Developer says to avoid ProgressDialog to indicate loading, and instead, to put an activity indicator right in the layout.

Progress & Activity @ Android Developer discusses activity indicators, but doesn't name the classes used. I've had no luck searching for Android classes with names like ActivityBar, ActivityCircle, or ActivityIndicator.

Where can I find documentation (tutorials, examples, or API documentation) on Android's support for including activity indicators right in my layout, avoiding a ProgressDialog?

Update: full.stack.ex pointed me the right answer.

First, include the following code in the Activity's onCreate() method before invoking setContentView():

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

Next, just before loading (e.g. firing up an AsyncTaskLoader), use this call to make the spinner appear:

setProgressBarIndeterminateVisibility(true);

Finally, after the load is completed, hide the spinner again:

MainActivity.this.setProgressBarIndeterminateVisibility(false);

Bingo! No ProgressDialog required. Making the spinner visible seems to slow down loading considerably in the emulator (it takes minutes instead of seconds), but not on my actual phone. I'm not sure if there's any way to make the spinner use fewer CPU cycles.

Canuck
  • 565
  • 4
  • 13

3 Answers3

5

It's not really obvious from the documentation that there's a window feature for that.

It's a built-in progress indicator:

Activity.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

developer.android.com/reference/android/app/Activity.html#requestWindowFeature(int)

full.stack.ex
  • 1,747
  • 2
  • 11
  • 13
1

You're talking about ProgressBar class (I guess): http://developer.android.com/reference/android/widget/ProgressBar.html

XorOrNor
  • 8,868
  • 12
  • 48
  • 81
  • Yes, but I was looking for the built-in support mentioned in the links I included. I could also add a ProgressBar to my layout, but the comment from full.stack.ex pointed me in a simpler direction. – Canuck Jan 23 '13 at 20:31
1

Ive tended to use an animated gif image in the past. Good site for generating them is

http://www.ajaxload.info/

ElPedro
  • 576
  • 10
  • 17