Spinner Fragment: show loading progress bar
– Android TV app hands on Tutorial Appendix A

In the Appendix of this Tutorial, I will introduce useful Android common library/function. These are usually applicable not only for Android TV, but also for Android phone/tablet device as well.


Spinner Fragment – show loading progress bar

While user is downloading big contents from web, you might want to show progress bar to notify user that some process (in this time downloading) is being done in background. It helps navigating user to wait this process.

Here, SpinnerFragment can be used to show circle arrow progress bar. Starting by making class by right click on “ui” package → [New] → [Java Class] → put Name as “SpinnerFragment”.

This class is a subclass of Fragment, and it is just making ProgressBar in onCreateView


Usage of Spinner Fragment – AsyncTask

Put button in MainFragment

To introduce the usage of SpinnerFragment, make button to show this Fragment. I will make “Spinner” button in MainFragment.

After click “Spinner” button, ShowSpinnerTask starts, which is explained following. 

AsyncTask implementation

Use case of SpinnerFragment is when something is processed in background, and AsyncTask is a one popular choice to do something in background.

Below, ShowSpinnerTask is introduced as a innerclass of MainFragment. It is mock example how to use SpinnerFragment. SpinnerFragment is added to the MainFragment before background process starts (onPreExecute), and removed after background process finishes (onPostExecute). This add and remove is done by using FragmentManager.

Adding and removing SpinnerFragment is enough. We don’t need to specify any animation, and UI update process during the background process is required.

In the first argument of add method, we need to specify an layout id of ViewGroup to attach SpinnerFragment. In this example main_browse_fragment is used.


Build and run


SpinnerFragment: circle type progressbar

When “Spinner” button is pressed, circle type progress bar will appear.

Source code is on github.


Sponsored Links

One response

Leave a Reply

Your email address will not be published.