import com.farsunset.ichat.example.R;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
public class DateReportActivity extends Activity {
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_date_report);
showProgressDialog("提示", "正在加载......");
}
/*
* 提示加载
*/
public void showProgressDialog(String title, String message) {
if (progressDialog == null) {
progressDialog = ProgressDialog.show(DateReportActivity.this, title,
message, true, false);
} else if (progressDialog.isShowing()) {
progressDialog.setTitle(title);
progressDialog.setMessage(message);
}
progressDialog.show();
}
/*
* 隐藏提示加载
*/
public void hideProgressDialog() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}
ProgressDialog 继承自AlertDialog,AlertDialog继承自Dialog,实现DialogInterface接口。
ProgressDialog的创建方式有两种,一种是new Dialog ,一种是调用Dialog的静态方法Dialog.show()。
- // 方式一:new Dialog
- final ProgressDialog dialog = new ProgressDialog(this);
- dialog.show();
- // 方式二:使用静态方式创建并显示,这种进度条只能是圆形条,设置title和Message提示内容
- ProgressDialog dialog2 = ProgressDialog.show(this, "提示", "正在登陆中");
- // 方式三 使用静态方式创建并显示,这种进度条只能是圆形条,这里最后一个参数boolean indeterminate设置是否是不明确的状态
- ProgressDialog dialog3 = ProgressDialog
- .show(this, "提示", "正在登陆中", false);
- // 方式四 使用静态方式创建并显示,这种进度条只能是圆形条,这里最后一个参数boolean cancelable 设置是否进度条是可以取消的
- ProgressDialog dialog4 = ProgressDialog.show(this, "提示", "正在登陆中",
- false, true);
- // 方式五 使用静态方式创建并显示,这种进度条只能是圆形条,这里最后一个参数 DialogInterface.OnCancelListener
- // cancelListener用于监听进度条被取消
- ProgressDialog dialog5 = ProgressDialog.show(this, "提示", "正在登陆中", true,
- true, cancelListener);
关于方式五的监听:
- private OnCancelListener cancelListener = new OnCancelListener() {
-
- @Override
- public void onCancel(DialogInterface dialog) {
- // TODO Auto-generated method stub