源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android编程实现加载等待ProgressDialog的方法

  • 时间:2021-08-25 02:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android编程实现加载等待ProgressDialog的方法
本文实例讲述了Android编程实现加载等待ProgressDialog的方法。分享给大家供大家参考,具体如下: 显示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的交互 希望本文所述对大家Android程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部