English | Site Directory

Android - An Open Handset Alliance Project

android.widget
public class

android.widget.ProgressBar

java.lang.Object
android.view.View Drawable.Callback KeyEvent.Callback
android.widget.ProgressBar

Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has progressed; the application can change the amount of progress (modifying the length of the bar) as it moves forward. There is also a secondary progress displayable on a progress bar which is useful for displaying intermediate progress, such as the buffer level during a streaming playback progress bar.

A progress bar can also be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation. This mode is used by applications when the length of the task is unknown.

The following code example shows how a progress bar can be used from a worker thread to update the user interface to notify the user of progress:

 public class MyActivity extends Activity {
     private static final int PROGRESS = 0x1;

     private ProgressBar mProgress;
     private int mProgressStatus = 0;

     private Handler mHandler = new Handler();

     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.progressbar_activity);

         mProgress = (ProgressBar) findViewById(R.id.progress_bar);

         // Start lengthy operation in a background thread
         new Thread(new Runnable() {
             public void run() {
                 while (mProgressStatus < 100) {
                     mProgressStatus = doWork();

                     // Update the progress bar
                     mHandler.post(new Runnable() {
                         public void run() {
                             mProgress.setProgress(mProgressStatus);
                         }
                     });
                 }
             }
         }).start();
     }
 }
 

XML attributes

See ProgressBar Attributes, View Attributes

Summary

XML Attributes inherited from class android.view.View
Constants inherited from class android.view.View
Fields inherited from class android.view.View

Public Constructors

          ProgressBar(Context context)
Create a new progress bar with range 0...100 and initial progress of 0.
          ProgressBar(Context context, AttributeSet attrs, Map inflateParams)
          ProgressBar(Context context, AttributeSet attrs, Map inflateParams, int defStyle)

Public Methods

        Drawable  getIndeterminateBackground()

Get the drawable used to draw the progress bar in indeterminate mode.

  synchronized      int  getMax()

Return the upper limit of this progress bar's range.

  synchronized      int  getProgress()

Get the progress bar's current level of progress.

  synchronized      int  getSecondaryProgress()

Get the progress bar's current level of secondary progress.

  synchronized  final    void  incrementProgressBy(int diff)

Increase the progress bar's progress by the specified amount.

  synchronized  final    void  incrementSecondaryProgressBy(int diff)

Increase the progress bar's secondary progress by the specified amount.

  synchronized      boolean  isIndeterminate()

Indicate whether this progress bar is in indeterminate mode.

        void  postInvalidate()
Cause an invalidate to happen on a subsequent cycle through the event loop.
        void  setBackground(Drawable d)
Set the background to a given Drawable, or remove the background.
  synchronized      void  setIndeterminate(boolean indeterminate)

Change the indeterminate mode for this progress bar.

        void  setIndeterminateBackground(Drawable background)

Define the background used to draw the progress bar in indeterminate mode.

  synchronized      void  setMax(int max)

Set the range of the progress bar to 0...

  synchronized      void  setProgress(int progress)

Set the current progress to the specified value.

  synchronized      void  setSecondaryProgress(int secondaryProgress)

Set the current secondary progress to the specified value.

        void  setVisibility(int v)
Set the enabled state of this view.

Protected Methods

  synchronized      void  onDraw(Canvas canvas)
Implement this to do your drawing.
  synchronized      void  onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

        void  startAnimation()

Start the indeterminate progress animation.

        void  stopAnimation()

Stop the indeterminate progress animation.

Methods inherited from class android.view.View