I want to show a progress Circle in my app while loading data. I have an activity and moving from one activity to another I am parsing some xml data so for the time being until the parsing is completed I want to show a circular loading effect.
-
2This is how I did it http://stackoverflow.com/questions/19655715/progress-dialog-is-closed-when-touch-on-screen/22939109#22939109 – Ali Apr 29 '14 at 09:45
7 Answers
You can use an indeterminate ProgressBar for the circular loading effect. Here is how you do it in XML:
<ProgressBar android:indeterminate="true"
android:layout_width="50dp" android:layout_height="50dp"
android:id="@+id/marker_progress" style="?android:attr/progressBarStyle"
android:layout_gravity="center_vertical|center_horizontal"/>
You can change the height and width to be what you want. When you are done loading, you can change it's visibility to View.INVISIBLE or View.GONE

- 38,516
- 9
- 41
- 49
You need to create animation xml file in res/anim folder and call startAnimation in your ImageView when you are loading data and stopAnimation when you stop loading data. And set loading image to ImageView, for example:
This id code for circle animation xml file
<?xml version="1.0" encoding="UTF-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="1200"
android:interpolator="@android:anim/linear_interpolator" />

- 21,988
- 13
- 81
- 109

- 327
- 2
- 12
-
I am using a List view with custom adapter. and i want to show the loading effect in that list view. how i can get that parsing is done and we can stop this animation – ta54 Mar 10 '11 at 13:36
-
I am using List view too. And when another thread parsing xml, i set to lost view special loadingAdapter wich return only one view. This view is imageView that fill all parent and fit image to center. When parsing thread stop parse i set to lest view my another custom Adapter wich provides UI elements. – RomaTTi Mar 10 '11 at 13:47
-
Insert this beetween two View tags
<ProgressBar android:id="@+id/loading_spinner"
style="?android:progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

- 2,470
- 3
- 27
- 36
Why not use the progressbar UI
myProgressDialog = ProgressDialog.show(ListingPage.this,"Please Wait", "Loading Date", true);
dan

- 1,891
- 17
- 20
-
i Cant use this progressDialog cause my client doesn't want this he want the circular loading effect. – ta54 Mar 10 '11 at 12:43
-
1
Use AsyncTask for loading and parsing:
/**
* Background task that fetched the content from server and parses the content.
*/
private class BackgroundLoadingTask extends AsyncTask<InputStream, Void, Boolean> {
@Override
protected void onPreExecute() {
// show the progress bar
Activity.this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Activity.this.requestWindowFeature(Window.PROGRESS_VISIBILITY_ON);
}
@Override
protected Boolean doInBackground(InputStream... params) {
// try to load XML from HTTP server and parse
return true;
}
@Override
protected void onPostExecute(Boolean parsingError) {
// hide the progress bar
Activity.this.requestWindowFeature(Window.PROGRESS_VISIBILITY_OFF);
}
}

- 17,370
- 11
- 72
- 79
-
1beware that not all of those features will work if you have gone full screen or hidden the title bar. – Anthony Graglia Mar 10 '11 at 14:09
-
`android.util.AndroidRuntimeException: requestFeature() must be called before adding content` – dentex Sep 16 '13 at 13:10
To expand a bit on trgraglia's answer, you could create an indeterminate (behavior: cycle) progress bar and set the visibility to false. During AsyncTask preExecute(), make it visible, and during AsyncTask onPostExecute(), turn it back to invisible (provided you are staying on the same activity or w/e case you may need). This eliminates the need to create an animation.

- 143
- 3
- 7
Just as you would the progress dialog, use an animation instead with async task and just make it visible on prexecution and hide it again on post.

- 5,355
- 5
- 46
- 75