I have a
ListView in my second
activity.OnItemClick of it I called a webservice and trying to fetch data. And after that I am moving to third activity which also have a
ListView having description of previous activities
I want to display a progress dialog before populating this
I don’t understand how to do it on
ListView? Does anybody know how to do it?
There are several methods of showing a progress bar (circle) while loading an
activity. In your case, one with a
ListView in it.
If you are using an
ActionBar, you can call the
ProgressBar like this (this could go in your
And after you are done displaying the list, to hide it.
IN THE LAYOUT (The XML)
And in your activity (Java)
I use an AsyncTask to fetch data for my lists. SO, in the AsyncTask’s
onPreExecute() I use something like this:
and in the
onPostExecute(), after setting the adapter to the
EDIT: This is how it looks in my app while loading one of several
You can do this easier.
It helped me.
After defining it in xml, you have to get its reference in java file
through ProgressBar class. Its syntax is given below:
After that you can make its disappear , and bring it back when needed
through setVisibility Method. Its syntax is given below:
I used this one for list view loading may helpful.
and my MainActivity class is,
this activity display progress for 3sec then it will display listview, instead of adding data statically to stringValues list you can get data from server in doInBackground() and display it.
Please use the sample at tutorialspoint.com. The whole implementation only needs a few lines of code without changing your xml file. Hope this helps.
STEP 1: Import library
STEP 2: Declare ProgressDialog global variable
STEP 3: Start new ProgressDialog and use the following properties (please be informed that this sample only covers the basic circle loading bar without the real time progress status).
STEP 4: If you are using AsyncTasks, you can start showing the dialog in onPreExecute method. Otherwise, just place the code in the beginning of your button onClick event.
STEP 5: If you are using AsyncTasks, you can close the progress dialog by placing the code in onPostExecute method. Otherwise, just place the code before closing your button onClick event.
Tested it with my Nexus 5 android v4.0.3. Good luck!
Are you extending ListActivity?
If so, put a circular progress dialog with the following line in your xml
Now, the progress indicator will show up till you have all your listview information, and set the Adapter. At which point, it will go back to the listview, and the progress bar will go away.
Create an xml file any name (say progressBar.xml) in drawable
<color name="silverGrey">#C0C0C0</color> in color.xml.
Now in your xml file where you have your listView add this code:
In AsyncTask in the method:
And in onPostExecute:
You can add the
ProgressBar to listview footer:
when the data is loaded to the adapter view call:
I suggest you when working with listview or recyclerview to use SwipeRefreshLayout. Like this
Only wrap your view and this will create an animation of refresh when loading data or by swipping down the screen as we can do in many apps.
Here’s the documentation of how to use it:
Happy coding !
Use This Within button on Click option or your needs:
I am using this: