ProgressDialog

Hi Guys!

Today I am going to share the code about the ProgressDialog in android.
A dialog showing a progress indicator and an optional text message or view. Only a text message or a view can be used at the same time.
More About the progress dialog and progress bar then visit the android developer site Progress Dialog.

Now lets start the coding about the progress dialog in android that will execute inside the doInBackground() of Asynctask till.

activity_main.xml



    

    

    

MainActivity.java

package com.sunil.progressdialog;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
  
 Button buttonStart;
 ProgressBar progressBar;
 ProgressDialog progressDialog;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      buttonStart = (Button)findViewById(R.id.start);
      progressBar = (ProgressBar)findViewById(R.id.progressbar);
     
      buttonStart.setOnClickListener(new Button.OnClickListener(){
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    buttonStart.setClickable(false);
    new asyncTaskUpdateProgress().execute();
   }
        
      });
     
  }
  public class asyncTaskUpdateProgress extends AsyncTask {
   int progress1;
    
  @Override
  protected void onPostExecute(Void result) {
   buttonStart.setClickable(true);
   progressDialog.dismiss();
  }
  @Override
  protected void onPreExecute() {
   progress = 0;
   progressDialog = ProgressDialog.show(MainActivity.this, "ProgressDialog", "Running");
  }
  @Override
  protected void onProgressUpdate(Integer... values) {
   progressBar.setProgress(values[0]);
  }
  @Override
  protected Void doInBackground(Void... arg0) {
 while(progress1<100 data-blogger-escaped-null="" data-blogger-escaped-pre="" data-blogger-escaped-progress1="" data-blogger-escaped-publishprogress="" data-blogger-escaped-return="" data-blogger-escaped-systemclock.sleep=""> 
 You can download the source code Progress Dialog
 
Cheers Guys! 

2 comments:

Debug Database in Android

In my last tutorial, we have learned how we can use persistence database in android. We also understood which database wrapper we can use...

Contact Me

Name

Email *

Message *