.java代码如下:
package org.lxh.demo; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Hello extends Activity { public ProgressDialog myDialog = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 生命周期方法 super.setContentView(R.layout.main); // 设置要使用的布局管理器 Button btn = new Button(this); this.setContentView(btn);// 全屏幕显示按钮 btn.setText("请按下我运行程序..."); btn.setOnClickListener(new OnClickListenerImpl()); } private class OnClickListenerImpl implements OnClickListener { public void onClick(View arg0) { CharSequence strDialogTitle = "请稍等片刻..."; CharSequence strDialogBody = "正在运算中..."; myDialog = ProgressDialog.show(Hello.this, strDialogTitle, strDialogBody); new Thread() { @Override public void run() { try { sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } myDialog.dismiss(); } }.start(); } } }运行效果如下:
原文地址:http://blog.csdn.net/yayun0516/article/details/44080557