Articles → Android → Progress Dialog In Android
Progress Dialog In Android
What Is Progress Dialog?
Example
int counter = 0;
Handler handler;
android.app.ProgressDialog progressBar;
public void ClickEvent(View view) {
progressBar = new android.app.ProgressDialog(view.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("Processing");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
handler = new Handler();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while (counter <= 100) {
handler.post(new Runnable() {
@Override
public void run() {
progressBar.setProgress(counter);
}
});
try {
Thread.sleep(200);
if (counter >= 100)
progressBar.dismiss();
} catch (InterruptedException e) {
e.printStackTrace();
}
counter += 10;
}
}
});
thread.start();
}
Output
Click to Enlarge