显示progressDialog的类
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
public class ShowProgressDialog {
public static ProgressDialog wait;
public static void show(Context context,String msg,Thread thread) {
final Thread th = thread;
wait = new ProgressDialog(context);
//设置风格为圆形
wait.setProgressStyle(ProgressDialog.STYLE_SPINNER);
wait.setTitle(null);
wait.setIcon(null);
//设置提示信息
wait.setMessage(msg);
//设置是否可以通过返回键取消
wait.setCancelable(true);
wait.setIndeterminate(false);
//设置取消监听
wait.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
th.interrupt();
}
});
wait.show();
}
}
调用的时候显示progressDialog作为主线程,另起线程进行业务处理,等到业务处理完调用ShowProgressDialog.wait.dismiss();关闭progressDialog。处理完如需提示信息,直接在业务线程中是不行的,需要通过Handler实现线程和activity的交互