ProgressDialog显示进度,但是这个显示进度是用Handler的handleMessage中来处理的

package com.example.androidtest;import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Message;public class MainActivity extends Activity {CharSequence[] items = {"Google", "Apple", "Microsoft"};boolean[] itemsChecked = new boolean[items.length];private ProgressDialog _progressDialog;private int _progress = 0;private Handler _progressHandler;public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button btn = (Button)findViewById(R.id.btn_dialog);btn.setOnClickListener(new Button.OnClickListener(){public void onClick(View v) {showDialog(1);_progress = 0;_progressDialog.setProgress(0);_progressHandler.sendEmptyMessage(0);}});_progressHandler = new Handler() {public void handleMessage(Message msg) {super.handleMessage(msg);if (_progress >= 100) {_progressDialog.dismiss();} else {_progress++;_progressDialog.incrementProgressBy(1);_progressHandler.sendEmptyMessageDelayed(0, 100);}}};}    protected Dialog onCreateDialog(int id) {switch (id) {case 0:return new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setTitle("This is a dialog with some simple text...").setPositiveButton("OK", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubToast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show();}}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubToast.makeText(getBaseContext(), "Cancel clicked!", Toast.LENGTH_SHORT).show();}}).setMultiChoiceItems(items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which, boolean isChecked) {// TODO Auto-generated method stubToast.makeText(getBaseContext(), items[which] + (isChecked ? " checked!" : " unchecked!"), Toast.LENGTH_SHORT).show();}}).create();case 1:_progressDialog = new ProgressDialog(this);_progressDialog.setIcon(R.drawable.ic_launcher);_progressDialog.setTitle("Downloading files...");_progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);_progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Hide", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubToast.makeText(getBaseContext(), "Hide clicked!", Toast.LENGTH_SHORT).show();}});_progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubToast.makeText(getBaseContext(), "Cancel clicked!", Toast.LENGTH_SHORT).show();}});return _progressDialog;}return null;}}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent" >
<TextView  android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello_world" />
<Buttonandroid:id="@+id/btn_dialog"android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Click to display a dialog" />
</LinearLayout>

Dialog的使用(三):progressDialog相关推荐

  1. 自定义实现ProgressDialog样式的Dialog

    1.  建立一个my_progress_dialog.xml布局文件 <?xml version="1.0" encoding="utf-8"?> ...

  2. Android 对话框(Dialog)大全 建立你自己的对话框

    Android 对话框(Dialog)大全 建立你自己的对话框 创建对话框 一个对话框一般是一个出现在当前Activity之上的一个小窗口. 处于下面的Activity失去焦点, 对话框接受所有的用户 ...

  3. android 获取对话框对象,Android 基本Dialog和自定义Dialog

    Android 基本Dialog和自定义Dialog Dialog类是对话框的基类,但你应该避免直接实例化Dialog ,可以使用子类 1.AlertDialog 此对话框可以显示标题,最多三个按钮, ...

  4. Android各种dialog

    Android Dialog之 提示对话框,单选对话框,复选对话框,列表对话框,日期对话框,时间对话框,自定义对话框,以及进度对话框. 上代码: import java.util.Calendar; ...

  5. Android Dialog用法

    摘要: 创建对话框 一个对话框一般是一个出现在当前Activity之上的一个小窗口. 处于下面的Activity失去焦点, 对话框接受所有的用户交互. 对话框一般用于提示信息和与当前应用程序直接相关的 ...

  6. android activity获取dialog对象,Android开发笔记之:Dialog的使用详解

    Dialog是任何系统都必须有的一个控件,作为辅助窗口,用于显示一些消息,或请求用户采取一引起操作等. 在Android中也不例外,基本使用可能参看文档. 使用时的注意事项1. BACK键能取消掉对话 ...

  7. Android Dialog

    创建对话框 Showing a Dialog 显示对话框 Dismissing a Dialog 解除对话框 Using dismiss listeners 使用解除监听器 Creating an A ...

  8. Dialogs 介绍 和 dialog.setContentView(R.layout.custom_dialog);

    Dialogs 对话框通常是一个显示在当前活动前面的小窗口.下面的活动失去焦点而由对话框接受所有的用户交互.对话框通常被用来当做通知或者运行中的应用程序相关的短暂活动. Android API支持下面 ...

  9. 对话框(Dialog)

    一.对话框(Dialog) 对话框就是程序与用户,或用户与程序进行人机交互.比如说当我们退出某个程序时会弹出是否退出的对话框等等. 代码: <LinearLayout xmlns:android ...

最新文章

  1. seaborn使用violinplot函数可视化小提琴图、使用stripplot函数添加抖动数据点(jittered points)、显示数据的稠密程度
  2. The following packages will be SUPERCEDED by a higher-priority channel
  3. 对等网不要求文件服务器,对等网文件共享技术研究与应用
  4. 【JavaScript】父子页面之间跨域通信的方法
  5. #1300 : 展胜地的鲤鱼旗(dp)
  6. html5网页动画总结--jQuery旋转插件jqueryrotate
  7. 重构-改善既有代码的设计(1)
  8. 谈谈你对IOC的理解
  9. BAT频繁与移动医疗挂钩 预示行业即将爆发?
  10. 博文视点大讲堂35期《Google Android创赢路线与产品开发实战》读者见面会
  11. python 判断中文字符数量_python判断列表里数量python中文乱码问题大总结
  12. OI生涯回忆录(Part5:至初中竞赛生涯完)
  13. 简单实用流程图模板分享,建议收藏
  14. 2353563-50-3,Thalidomide-O-PEG4-Acid一种鱼精蛋白连接物,在活化剂EDC或HATU存在下可与含胺部分反应
  15. 火焰识别python_五行属火的字大全
  16. [MFC] CList
  17. 2019年二级造价工程师讲义视频课件免费下载地址
  18. 阿里滑块,X82Y,解决方案
  19. 带宽与码元的关系_数据速率、载波频率和带宽的关系
  20. 如何围绕某一轴(不是xyz)旋转——transform.RotateAround

热门文章

  1. MySQL 5.6.6 LABS 版本 下载 已经内含 Memcached
  2. tomcat cpu占用过高,系统负载高问题跟踪
  3. python基础教程视频(全13集)-Python基础视频教程(600集)【传智播客精品教程】...
  4. python详细安装教程环境配置-python环境安装详细步骤
  5. python英语字典程序-Pyqt5实现英文学习词典
  6. python界面图片-python如何实现读取并显示图片(不需要图形界面)
  7. python一个月能学成嘛-学过 Python 的人没有告诉你,年入百万有多难
  8. python为什么中文要encoding-python中encoding是什么意思
  9. python飞机大战源代码-python版飞机大战代码分享
  10. 爬虫python的爬取步骤-Python爬虫爬取数据的步骤