Reputation: 574
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.
Upvotes: 7
Views: 2276
Reputation: 1747
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)
Upvotes: 5
Reputation: 586
Ive tended to use an animated gif image in the past. Good site for generating them is
Upvotes: 1
Reputation: 8978
You're talking about ProgressBar class (I guess): http://developer.android.com/reference/android/widget/ProgressBar.html
Upvotes: 1