Home » Android » android – how to show progress bar(circle) in an activity having a listview before loading the listview with data

android – how to show progress bar(circle) in an activity having a listview before loading the listview with data

Posted by: admin March 11, 2020 Leave a comment

Questions:

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 ListView item.

I want to display a progress dialog before populating this ListView.

I don’t understand how to do it on ListView? Does anybody know how to do it?

My Code-

ThirdActivity.java

thirdactivity.xml

How to&Answers:

There are several methods of showing a progress bar (circle) while loading an activity. In your case, one with a ListView in it.

IN ACTIONBAR

If you are using an ActionBar, you can call the ProgressBar like this (this could go in your onCreate()

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 ListView:

EDIT: This is how it looks in my app while loading one of several ListViews

enter image description here

Answer:

You can do this easier.
Source: http://www.tutorialspoint.com/android/android_loading_spinner.htm
It helped me.

Layout:

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:

Answer:

I used this one for list view loading may helpful.

activity_main.xml

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.

Answer:

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!

Answer:

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.

Answer:

Answer:

Create an xml file any name (say progressBar.xml) in drawable
and add <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:

Answer:

You can add the ProgressBar to listview footer:

layout/progress_bar.xml

when the data is loaded to the adapter view call:

Answer:

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:
https://developer.android.com/training/swipe/add-swipe-interface.html
https://developer.android.com/training/swipe/respond-refresh-request.html

Happy coding !

Answer:

Use This Within button on Click option or your needs:

Answer:

Process Bar:

Dependency:

XML:

In Res->color

In Main:

Answer:

I am using this: