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


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, November 24, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250