android学习笔记20——ProgressDialog进度条对话框
ProgressDialog==>进度条对话框
ProgressDialog本身就代表一个进度条对话框,程序只需要创建ProgressDialog实例,并将其显示出来就是一个进度条对话框;开发者也可以设置进度对话框里进度条的方法。
包含了如下常用方法:
1.setIndeterminate(boolean indeterminate):设置对话框里的进度条是否显示进度值;
2.setMax(int max):设置对话框里进度条的最大值;
3.setMessage(CharSequence message):设置对话框里显示的消息;
4.setProgress(int value):设置对话框里进度条的进度值;
5.setProgressStyle(int style):设置对话框里进度条的风格;
实例如下:
布局文件==》
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <EditText
android:id="@+id/edtContent"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <Button
android:id="@+id/btnexec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="progressDialog" /> </LinearLayout> 代码实现==》
package com.example.myprogressdialog1; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class MainActivity extends Activity
{
private int[] date = new int[100];
private int hasDate = 0;
final int progress_Dialog = 0x112;
private int progressStatus = 0;
private ProgressDialog pd;
private Handler handler; @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Button btnexec = (Button) this.findViewById(R.id.btnexec);
btnexec.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
showDialog(progress_Dialog);
}
});
handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
if (msg.what == 0x112)
{
pd.setProgress(progressStatus);
}
}
};
} @Override
protected Dialog onCreateDialog(int id, Bundle args)
{
System.out.println("---------------create---------------");
switch (id)
{
case progress_Dialog:
pd = new ProgressDialog(this);
pd.setMax(100);
pd.setTitle("任务完成百分比");
pd.setMessage("耗时任务完成百分比");
// 设置对话框取消按钮不可用
pd.setCancelable(false);
// 设置对话框进度条样式风格
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// 设置对话框的进度条是否显示进度
pd.setIndeterminate(true);
break;
}
return pd;
} // 该方法将在onCreateDialog()调用之后被回调
@Override
protected void onPrepareDialog(int id, Dialog dialog)
{
System.out.println("-----------------prepare-----------------");
super.onPrepareDialog(id, dialog);
switch (id)
{
case progress_Dialog:
pd.incrementSecondaryProgressBy(-pd.getProgress());
new Thread()
{
public void run()
{
while (progressStatus < 100)
{
progressStatus = doWork();
Message msg = new Message();
msg.what = 0x112;
handler.sendMessage(msg);
}
if (progressStatus >= 100)
{
pd.dismiss();// 关闭对话框
}
}
}.start();
break;
}
} private int doWork()
{
date[hasDate++] = (int) (Math.random() * 100);
try
{
Thread.sleep(100);
} catch (InterruptedException e)
{
e.printStackTrace();
}
return hasDate;
} @Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
运行效果:

android学习笔记20——ProgressDialog进度条对话框的更多相关文章
- Android学习笔记_76_Android ProgressBar 进度条
android 进度条的样式 例1:(默认样式(中等圆形))Xml代码 <ProgressBar android:id="@+id/progressBar1" ...
- 【转】【Android】ProgressDialog进度条对话框的使用
Android ProgressDialog进度条对话框的使用: 转自:http://aina-hk55hk.iteye.com/blog/679134/ <?xml version=" ...
- 【转】24. android dialog ——ProgressDialog 进度条对话框详解
原文网址:http://blog.csdn.net/jamesliulyc/article/details/6375598 首先在onCreateDialog方法里创建一个ProgressDialog ...
- Android——ProgressDialog 进度条对话框
public class ProgressDialogActivity extends Activity { private Button btn_large_pd, btn_horizonta ...
- Android学习笔记_81_Android ProgressDialog ProgressBar 各种效果
1,弹出Dialog 屏幕不变暗. 创建一个样式就OK了:在styles.xml文件里添加样式: 1, <style name="dialog" parent="@ ...
- ProgressDialog进度条对话框
(一) 1.效果图: 2.activity_main.xml <?xml version="1.0" encoding="utf-8"?> < ...
- Android学习笔记(20)————利用ListView制作带竖线的多彩表格
http://blog.csdn.net/conowen/article/details/7421805 /********************************************** ...
- Android学习笔记(20):时钟(AnalogClock和TextClock)和计时器(Chronometer)
时钟文本TextClock继承自TextView.是用于显示当前时间的文本框. TextClock支持的XML属性和相关方法 XML属性 相关方法 说明 android:format12Hour se ...
- Android 进度条对话框ProgressDialog
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
随机推荐
- addcontentView之后如何让这个view消失掉
Dia dialog ; public void go(View view){ dialog = (Dia) getLayoutInflater().inflate(R.layout.main, nu ...
- yii2数据修改|联查
model 层 联查 $con = Yii::$app->db; $re = $con->createCommand("select * from ads LEFT JOIN ...
- 83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- TensorFlow简单介绍和在centos上的安装
##tensorflow简单介绍: TensorFlow™ is an open source software library for numerical computation using dat ...
- C++ Primer : 第十二章 : 动态内存之动态内存管理(new和delete)
C++语言定义了两个运算符来分配和释放动态内存:运算符new分配内存,运算符delete释放new分配的内存. 运算符new和delete 使用new动态分配和初始化对象 在自由空间分配的内存是无名的 ...
- makefile--模式规则(七)
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 上一节讲到目录创建成功,目标文件没有生产到对应目录下,这里我们先给目标文件加上对应目录,这样的话 ...
- ubuntu 双屏问题的解决方案
ubuntu有一个很让人头疼的问题就是它默认开启双屏.只要你有两个显示器接口,即使你没有两块屏幕,它也是按照双屏幕去显示. 这就会造成一些很让人无语的问题,比如,恰好跳到你没有的那个屏幕就可能导致无法 ...
- PCL可视化显示 直接加载显示pcb文件
简单可视化类,是指直接在程序中使用,而且不支持多线程. #include<iostream> #include<pcl\point_cloud.h> #include<p ...
- spark新能优化之多次使用RDD的持久化或checkPoint
如果程序中,对某一个RDD,基于它进行了多次transformation或者action操作.那么就非常有必要对其进行持久化操作,以避免对一个RDD反复进行计算. 此外,如果要保证在RDD的持久化数据 ...
- hdu1213 并查集
题意:有 n 个朋友,他们可能相互认识,A 认识 B,B 认识 C,则 ABC 相互认识,现在给出他们的认识情况,相互认识的人坐一桌,否则需要分开坐,问至少需要多少桌. 其实就是问并查集的个数,在初始 ...