Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Progress bar

1.
Mobile Computing - MCA 650003
Mr. Pritesh N. Patel Page 1
 ProgressBar
java.lang.Object
↳android.view.View
↳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 without an indication of progress. This
mode is used by applications when the length of the task is unknown. The
indeterminate progress bar can be either a spinning wheel or a horizontal bar.
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);
}
});
}
}

2.
Mobile Computing - MCA 650003
Mr. Pritesh N. Patel Page 2
}).start();
}
}
To add a progress bar to a layout file, you can use the <ProgressBar> element.
By default, the progress bar is a spinning wheel (an indeterminate indicator). To
change to a horizontal progress bar, apply the Widget.ProgressBar.Horizontal
style, like so:
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
... />
If you will use the progress bar to show real progress, you must use the horizontal
bar.
You can then increment the progress with incrementProgressBy() or setProgress().
By default, the progress bar is full when it reaches 100. If necessary, you can
adjust the maximum value (the value for a full bar) using
the android:max attribute. Other attributes available are listed in table.
Another common style to apply to the progress bar is Widget.ProgressBar.Small,
which shows a smaller version of the spinning wheel—useful when waiting for
content to load.
For example, you can insert this kind of progress bar into your default layout for a
view that will be populated by some content fetched from the Internet—the
spinning wheel appears immediately and when your application receives the
content, it replaces the progress bar with the loaded content.
For example:
<LinearLayout
android:orientation="horizontal"
... >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Small"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/loading" />
</LinearLayout>

4.
Mobile Computing - MCA 650003
Mr. Pritesh N. Patel Page 4
 SeekBar
java.lang.Object
↳ android.view.View
↳ android.widget.ProgressBar
↳ android.widget.AbsSeekBar
↳ android.widget.SeekBar
A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user
can touch the thumb and drag left or right to set the current progress level or use
the arrow keys. Placing focusable widgets to the left or right of a SeekBar is
discouraged.
Clients of the SeekBar can attach a SeekBar.OnSeekBarChangeListener to be notified of
the user's actions.
Public Constructors
SeekBar(Context context)
SeekBar(Context context, AttributeSet attrs)
SeekBar(Context context, AttributeSet attrs, int defStyle)
Public Methods
void setOnSeekBarChangeListener(SeekBar.OnSeekBarChangeListener L)
Sets a listener to receive notifications of changes to the SeekBar's progress level.
abstract void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
Notification that the progress level has changed.
abstract void onStartTrackingTouch(SeekBar seekBar)
Notification that the user has started a touch gesture.
abstract void onStopTrackingTouch(SeekBar seekBar)
Notification that the user has finished a touch gesture.
Explanation
public abstract void onProgressChanged (SeekBar seekBar, int progress, boolean
fromUser)

5.
Mobile Computing - MCA 650003
Mr. Pritesh N. Patel Page 5
Notification that the progress level has changed. Clients can use the fromUser
parameter to distinguish user-initiated changes from those that occurred
programmatically.
Parameters
seekBar The SeekBar whose progress has changed
progress
The current progress level. This will be in the range 0..max where max was set
by setMax(int). (The default value for max is 100.)
fromUser True if the progress change was initiated by the user.
Demo Code Example
 Chronometer
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
↳ android.widget.Chronometer
You can give it a start time in the elapsedRealtime() timebase, and it counts up from that,
or if you don't give it a base time, it will use the time at which you call start(). By default it
will display the current timer value in the form "MM:SS" or "H:MM:SS", or you can use
setFormat(String) to format the timer value into an arbitrary string.
Nested Classes interface Chronometer.OnChronometerTickListener A callback that
notifies when the chronometer has incremented on its own.
Public Constructors
Chronometer(Context context)
Initialize this Chronometer object.
Chronometer(Context context, AttributeSet attrs)
Initialize with standard view layout information.
Chronometer(Context context, AttributeSet attrs, int defStyle)
Initialize with standard view layout information and style.
Public Methods
long
getBase()
Return the base time as set through setBase(long).
String
getFormat()
Returns the current format string as set through
setFormat(String).

7.
Mobile Computing - MCA 650003
Mr. Pritesh N. Patel Page 7
 RatingBar
java.lang.Object
↳ android.view.View
↳ android.widget.ProgressBar
↳ android.widget.AbsSeekBar
↳ android.widget.RatingBar
A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in
stars. The user can touch/drag or use arrow keys to set the rating when using the
default size RatingBar. The smaller RatingBar style ( ratingBarStyleSmall) and the
larger indicator-only style (ratingBarStyleIndicator) do not support user interaction
and should only be used as indicators.
When using a RatingBar that supports user interaction, placing widgets to the left
or right of the RatingBar is discouraged.
The number of stars set (via setNumStars(int) or in an XML layout) will be shown
when the layout width is set to wrap content (if another layout width is set, the
results may be unpredictable).
The secondary progress should not be modified by the client as it is used
internally as the background for a fractionally filled star.
Public Constructors
RatingBar(Context context, AttributeSet attrs, int defStyle)
RatingBar(Context context, AttributeSet attrs)
RatingBar(Context context)
Public Methods
int
getNumStars()
Returns the number of stars shown.
RatingBar.OnRatingBarChangeL
istener
getOnRatingBarChangeListener()
float
getRating()
Gets the current rating (number of stars filled).