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


Picture showing the output of progress dialog in android

Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250