Progress Bar is a visual indicator during some operation. This is to notify user to wait for complication of the particular progress. It may also indicate how far operation has been progressed.
In this tutorial we'll discuss how to create different types of Progress Bar in Android with example
Spinner Progress using ProgressDialog
ProgressDialog progressDialog;
private void showProgressDialog() {
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Downloading Video ...");
progressDialog.show();
// To Dismiss progress dialog
//progressDialog.dismiss();
}
|
Spinner Progress using ProgressDialog |
Spinner Progress using ProgressDialog with Title
ProgressDialog progressDialog;
private void showProgressDialogWithTitle() {
progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setCancelable(false);
progressDialog.setTitle("Please Wait..");
progressDialog.setMessage("Preparing to download ...");
progressDialog.show();
// To Dismiss progress dialog
//progressDialog.dismiss();
}
|
Spinner Progress using ProgressDialog with Title |
Horizontal Progress Bar using ProgressDialog
ProgressDialog progressDialog;
private int progressStatus = 0;
private Handler handler = new Handler();
private void showProgressDialogHorizontal() {
progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Please Wait..");
progressDialog.setMessage("Downloading Video ...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCancelable(false);
progressDialog.setMax(100);
progressDialog.show();
// Start lengthy operation in a background thread
new Thread(new Runnable() {
public void run() {
while (progressStatus < 100) {
try{
// Here I'm making thread sleep to show progress
Thread.sleep(200);
progressStatus += 5;
} catch (InterruptedException e){
e.printStackTrace();
}
// Update the progress bar
handler.post(new Runnable() {
public void run() {
progressDialog.setProgress(progressStatus);
}
});
}
progressDialog.dismiss();
}
}).start();
}
|
Horizontal Progress Bar using ProgressDialog |
I found spinner progress in your blog what i exactly needed..Android Training
ReplyDeleteThanks for the wonderful information .Free text to HTML converter
ReplyDeleteKeep sharing
Thanks, really useful!
ReplyDelete