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

 更新时间:2015年12月29日 14:37:11   作者:q757989418  
这篇文章主要介绍了Android编程实现加载等待ProgressDialog的方法,实例分析了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程序设计有所帮助。

相关文章

最新评论