package com.linquan.test.progressdialog;

 

import android.app.Activity;

import android.app.ProgressDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

 

public class test_ProgressDialog extends Activity {

 

private Button btn1,btn2;

int m_count = 0;

//声明进度条对话框

ProgressDialog m_pDialog;

 

/** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

        btn1 = (Button)this.findViewById(R.id.btn1);

        btn2 = (Button)this.findViewById(R.id.btn2);

        

        btn1.setOnClickListener(new Button.OnClickListener(){

 

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

m_pDialog = new ProgressDialog(test_ProgressDialog.this);

//设置进度条风格,风格为圆形的,旋转的

m_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

//设置标题

m_pDialog.setTitle("提示");

//设置提示信息

m_pDialog.setMessage("这是一个圆形进度条对话框");

//设置标题图片

m_pDialog.setIcon(R.drawable.icon);

//设置进度条是否不明确‍

m_pDialog.setIndeterminate(false);

//设置是否可按返回键取消

m_pDialog.setCancelable(true);

//设置一个按钮

m_pDialog.setButton("确定", new DialogInterface.OnClickListener(){

 

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

//点击确定按钮取消对话框

m_pDialog.cancel();

}

 

});

m_pDialog.show();

}

        

        });

        

        btn2.setOnClickListener(new Button.OnClickListener(){

 

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

m_count = 0;

m_pDialog = new ProgressDialog(test_ProgressDialog.this);

//设置进度条风格,风格为圆形的,旋转的

m_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

//设置标题

m_pDialog.setTitle("提示");

//设置提示信息

m_pDialog.setMessage("这是一个长形进度条对话框");

//设置标题图片

m_pDialog.setIcon(R.drawable.icon);

//设置进度条是否不明确

m_pDialog.setIndeterminate(false);

//设置是否可按返回键取消

m_pDialog.setCancelable(true);

m_pDialog.show();

 

new Thread(){

public void run(){

while(m_count <=100){

//由线程来控制进度条

m_pDialog.setProgress(m_count++);

try {

Thread.sleep(100);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

m_pDialog.cancel();

}

 

}.start();

}

        

        });

    }

}