private ProgressDialog mDialog;
protected void showDialog(String message, DialogInterface.OnDismissListener listener) {
if (mDialog == null)
mDialog = new ProgressDialog(this);
mDialog.setMessage(message);
mDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
if (listener != null) {
mDialog.setOnDismissListener(listener);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
mDialog.show();
}
});
}
protected void hideDialog() {
if (mDialog != null) {
mDialog.dismiss();
}
}
异步请求中片段代码:
@Override
protected void onPreExecute() {
showDialog("正在发送", new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
dialog.dismiss();
}
});
}
请求成功:
@Override
protected void onPostExecute(String jsonStr) {
hideDialog();
}