[TinyTut] - Displaying a simple ProgressDialog
What you learn: You will learn how to display a simple ProgressDialog.
Difficulty: 1.1 of 5

What it will look like:

Description:
Generally the life of a progress-bar is guided by the following lines:
Using java Syntax Highlighting
- ProgressDialog myProgressDialog = null;
- // ...
- myProgressDialog = ProgressDialog.show(TestLayout.this,
- "Please wait...", "Doing Extreme Calculations...", true);
- // ...
- // Do some Fake-Work
- // ...
- myProgressDialog.dismiss();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
As always, there are like 10[sup]60[/sup] Overloads, where you can define if your ProgressDialog should be determinate or indeterminate(in this case), should be cancleable, etc...
Here you get to know the most common ProgressBar.
If you want to digg some deeper, have a look here (search for ProgressBar).
This is a kind of proper "real-life-implementation":
Using java Syntax Highlighting
- package org.anddev.android.testproject;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- public class TestLayout extends Activity {
- ProgressDialog myProgressDialog = null;
- @Override
- public void onCreate(Bundle icicle){
- super.onCreate(icicle);
- /* Create a very simple button */
- Button b = new Button(this);
- this.setContentView(b);
- b.setText("Show ProgressBar...");
- /* Assign the OnClicklistener to it,
- * that will fake some work and
- * display a progress-bar */
- b.setOnClickListener(myProgressBarShower);
- }
- /** OnClickListener that fakes some work to be done. */
- OnClickListener myProgressBarShower = new OnClickListener(){
- // @Override
- public void onClick(View arg0) {
- // Display an indeterminate Progress-Dialog
- myProgressDialog = ProgressDialog.show(TestLayout.this,
- "Please wait...", "Doing Extreme Calculations...", true);
- new Thread() {
- public void run() {
- try{
- // Do some Fake-Work
- sleep(5000);
- } catch (Exception e) { }
- // Dismiss the Dialog
- myProgressDialog.dismiss();
- }
- }.start();
- }
- };
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Regards,
plusminus







