How:利用ProgressAialog创建进度条
来源:互联网 发布:outlook是什么软件 编辑:程序博客网 时间:2024/06/11 18:46
Creating a ProgressDialog
A ProgressDialog
is an extension of theAlertDialog
class that can display a progress animation in the form of a spinning wheel, for a task withprogress that's undefined, or a progress bar, for a task that has a defined progression.The dialog can also provide buttons, such as one to cancel a download.
Opening a progress dialog can be as simple as calling ProgressDialog.show()
. For example, the progress dialog shown to the right can be easily achieved without managing the dialog through theonCreateDialog(int)
callback,as shown here:
ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", "Loading. Please wait...", true);
The first parameter is the application Context
, the second is a title for the dialog (left empty), the third is the message, and the last parameter is whether the progressis indeterminate (this is only relevant when creating a progress bar, which isdiscussed in the next section).
The default style of a progress dialog is the spinning wheel.If you want to create a progress bar that shows the loading progress with granularity,some more code is required, as discussed in the next section.
Showing a progress bar
To show the progression with an animated progress bar:
- Initialize the ProgressDialog with the class constructor,
ProgressDialog(Context)
. - Set the progress style to "STYLE_HORIZONTAL" with
setProgressStyle(int)
and set any other properties, such as the message. - When you're ready to show the dialog, call
show()
or return the ProgressDialog from theonCreateDialog(int)
callback. - You can increment the amount of progress displayed in the bar by calling either
setProgress(int)
with a value for the total percentage completed so far orincrementProgressBy(int)
with an incremental value to add to the total percentage completed so far. - dismiss().
For example, your setup might look like this:
ProgressDialog progressDialog;progressDialog = new ProgressDialog(mContext);progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);progressDialog.setMessage("Loading...");progressDialog.setCancelable(false);
The setup is simple. Most of the code needed to create a progress dialog is actually involved in the process that updates it. You might find that it'snecessary to create a second thread in your application for this work and then report the progressback to the Activity's UI thread with a Handler
object. If you're not familiar with using additional threads with a Handler, see the example Activity below that uses a second thread toincrement a progress dialog managed by the Activity.
- How:利用ProgressAialog创建进度条
- How:利用DialogFrament创建进度条(该方法同样适用于其他Dialog的实现)
- 创建进度条
- 利用CProgressCtrl制作进度条
- 利用AsyncTask模拟进度条
- javascript事件小例子(利用ActiveX对象创建一个进度条)
- java 创建一个进度条
- 动态创建进度条对话框
- js 创建进度条
- 用Makefile 创建进度条
- bootstrap创建动态进度条
- 利用uploadprogress实现上传进度条
- How:为activity实现进度条(ProgressBar)
- 如何创建一个进度条控件
- SDK方式创建进度条控件
- C# GDI创建自定义进度条
- 进度条的创建与使用
- Android 动态创建圆形进度条
- String s = "a"+"b"+"c"+"d"共创建了多少个对象?
- Oracle BI产品线
- 一道C++面试题,只能修改或者增加一个字符,给出至少三种修改方案
- Wildfire:社交网络的商业影响
- jquery常用功能
- How:利用ProgressAialog创建进度条
- Windows Phone 7 培训总结
- properties文件编写注意点
- springAOP配置
- VMWare 虚拟机系统 ping 不通主机解决方案
- 第四周任务四
- spring管理数据库
- Windows Phone 7开发必备工具
- Android上HDMI介绍(基于高通平台)