Android编程实现加载等待ProgressDialog的方法
作者:q757989418 时间:2022-09-11 21:12: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程序设计有所帮助。
标签:Android,ProgressDialog
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java多线程复制文件的实例代码
2022-03-04 04:29:54
Java8实现对List<Integer>的求和
2023-12-08 07:03:51
![](https://img.aspxhome.com/file/2023/5/90985_0s.png)
java9新特性Collection集合类的增强与优化方法示例
2023-01-29 05:16:57
![](https://img.aspxhome.com/file/2023/4/61534_0s.png)
idea手动刷新git分支的详细教程
2022-04-05 11:53:43
![](https://img.aspxhome.com/file/2023/2/68182_0s.png)
SpringBoot整合ES解析搜索返回字段问题
2023-01-26 21:39:53
Java中简单实用Quartz概述
2021-09-09 14:16:30
Java建造者模式构建复杂对象的最佳实践
2021-06-27 10:07:16
![](https://img.aspxhome.com/file/2023/8/61808_0s.png)
Spring boot的上传图片功能实例详解
2022-10-09 09:52:00
c# winform时钟的实现代码
2023-04-05 07:40:53
C#中怎样从指定字符串中查找并替换字符串?
2023-09-30 14:26:24
![](https://img.aspxhome.com/file/2023/6/83236_0s.jpg)
关于SpringSecurity配置403权限访问页面的完整代码
2023-11-13 02:03:59
![](https://img.aspxhome.com/file/2023/3/86833_0s.png)
解决Mybatis-plus和pagehelper依赖冲突的方法示例
2022-06-28 16:52:59
![](https://img.aspxhome.com/file/2023/6/78226_0s.jpg)
浅谈java项目与javaweb项目导入jar包的区别
2023-11-11 11:06:19
剖析Java中阻塞队列的实现原理及应用场景
2023-09-01 17:33:07
C#给Excel添加水印实例详解
2022-02-01 22:30:51
![](https://img.aspxhome.com/file/2023/8/79058_0s.png)
C#设置文件权限的方法
2022-08-31 22:35:42
Java实现显示指定类型的文件
2021-10-26 11:30:37
![](https://img.aspxhome.com/file/2023/5/62675_0s.png)
java 使用BigDecimal进行货币金额计算的操作
2023-12-05 23:19:34
![](https://img.aspxhome.com/file/2023/9/90019_0s.jpg)
java实现给图片加铺满的网格式文字水印
2023-07-30 05:22:12
![](https://img.aspxhome.com/file/2023/9/57809_0s.jpg)
Java KeyGenerator.generateKey的19个方法代码示例
2022-08-08 14:26:40