How to implement a progress bar while loading data into a ListView?

1 answer 1

First of all, add the progress bar component to the xml markup:

<ProgressBar android:id="@+id/pbData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:visibility="gone" android:indeterminate="true"/> 

the value of the visibility parameter gone makes the component invisible.

Further in the code, before starting the data loading into the ListView, make the ProgressBar visible:

 mPbData.setVisibility(View.VISIBLE); 

After the data download is complete, the ProgressBar must be made invisible again:

 mPbData.setVisibility(View.GONE);