ProgressDialog 的用法:
package irdc.ex03_18;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class EX03_18 extends Activity
{
private Button mButton1;
private TextView mTextView1;
public ProgressDialog myDialog = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton1 =(Button) findViewById(R.id.myButton1);
mTextView1 = (TextView) findViewById(R.id.myTextView1);
mButton1.setOnClickListener(myShowProgressBar);
}
Button.OnClickListener myShowProgressBar =
new Button.OnClickListener()
{
public void onClick(View arg0)
{
final CharSequence strDialogTitle =
getString(R.string.str_dialog_title);
final CharSequence strDialogBody =
getString(R.string.str_dialog_body);
// EX03_18.this 指Content 不用直接用this
myDialog = ProgressDialog.show(EX03_18.this, strDialogTitle, strDialogBody,true);
mTextView1.setText(strDialogBody);
// 在后台程序运行完毕前,以dismiss()方法销毁,否则进入无限循环中 (起个子线程)
new Thread(){
@Override
public void run()
{
// TODO Auto-generated method stub
super.run();
try
{
Thread.sleep(4000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
myDialog.dismiss();
}
}
}.start();
};
};
}