首页 > 系统 > Android > 正文

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

2020-04-11 11:06:11
字体:
来源:转载
供稿:网友

本文实例讲述了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程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表