Friday, December 28, 2012

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! 

Rocky

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

0 comments:

Post a Comment

 

Copyright @ 2013 Android Developers Tipss.