How can I programmatically display an hourglass in an Android application ?
+11
A:
You can use a ProgressDialog
:
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Thinking...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
The above code will show the following dialog on top of your Activity
:
Alternatively (or additionally) you can display a Progress indicator in the title bar of your Activity
.
You need to request this as a feature near the top of the onCreate()
method of your Activity
using the following code:
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Then turn it on like this:
setProgressBarIndeterminateVisibility(true);
and turn it off like this:
setProgressBarIndeterminateVisibility(true);
Dave Webb
2010-01-26 15:11:52
The problem is that after displaying the dialog box I ran a relatively long treatment which prevents the display of the dialog box that appears at the end of treatment when I no longer need !
Arutha
2010-01-26 16:00:54
Have a look at `AsyncTask`. You display and hide the `ProgressDialog` in `onPreExecute()` and `onPostExecute` and do your work in `doInBackground`. http://android-developers.blogspot.com/2009/05/painless-threading.html
Dave Webb
2010-01-26 16:26:10
Might also be worth reading the Android Developer Guide "Designing For Responsiveness" http://developer.android.com/guide/practices/design/responsiveness.html
fiXedd
2010-01-26 17:02:11