A simple example of Android in ProgressDialog

Internet generally are an example of how the progress bar shows how close the end of the mandate is not an article, reference to other articles through the tests to set the progress bar shows a simple example is as follows:

The establishment of android and engineering work is omitted, Google click on it.

Here to introduce the main Activity

package com.lveyo.android.demo.progressbar;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ProgressBarDemo extends Activity {

        private TextView statusTextView;
        private Button beginBtn;
        private ProgressDialog progressDialog;

    public void onCreate(Bundle savedInstanceState) {
        statusTextView = (TextView)findViewById(R.id.status);
        beginBtn = (Button)findViewById(R.id.beginBtn);

     *  Used to update UI Handler
    private Handler handler = new Handler(){

                public void handleMessage(Message msg) {

                        // Close ProgressDialog

                        // Update the UI

         *  Click on the button event listener
    private void setListener(){
        beginBtn.setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {

                                // Show ProgressDialog
                                progressDialog = ProgressDialog.show(ProgressBarDemo.this, "Loading...", "Please wait...", true, false);

                                // Create a new thread
                                new Thread(){

                                        public void run() {
                                                // Need to spend time calculation method

                                                // To send a message handler



package com.lveyo.android.demo.progressbar;

 *  Schematic method
 * @author lveyo
public class Calculation {

        public static void calculate(int sleepSeconds){
                try {
                        Thread.sleep(sleepSeconds * 1000);
                } catch (Exception e) {
                        // TODO: handle exception


main.xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<TextView android:id="@+id/status"
<Button android:id="@+id/beginBtn"

In the android, usually we can not in a separate thread to update UI, but in the main thread, which is why we want to use Handler, and when the handler receive the message, it will put it into the queue waiting for the implementation of , generally speaking this will soon be executed.

A simple example of Android in ProgressDialog

分类:Mobile 时间:2010-03-29 人气:2222
blog comments powered by Disqus


  • public static void main (String args []) parameters 2010-05-15

    String args [] is the main function of main parameters, namely array of strings. Using eclipse in the editing, right-click to run the Java files in the Run As option, select Run Configurations. Main class in the Project and complete the project, resp

  • Why public static void main (String args []){} 2010-11-06

    main () is a Java program entry, program execution is the beginning of this entry. Class is a class member, main () method must be public members. So that it can be called in the execution environment. main () method does not produce the object can b

  • 为什么 main 方法是 public static void? 2014-01-16

    0.引言: 之前在校招时,旁边的面试官问过这样一个问题:如何不在 main 函数里打印出一行字符串呢(也不允许在main里调用函数)? 如果你不能回答上来没关系,看了本文你就会有了答案.其实 main 函数我们每天 coding 都会接触,但是不一定每个同学都了解或注意到它为什么要这么设计,为什么不能那么写? 言归正传,Main方法是我们学习Java编程语言时知道的第一个方法,你是否曾经想过为什么 main 方法是 public.static.void 的?当然,很多人首先学的是C和C++,但是

  • public static final naming convention 2010-07-12

    Has been, public static final variable is the standard name is all uppercase, words underlined between. The problem is, we really feel IS_HAS_CERTIFIED better than IsHasCertified you read a good maintenance. Public static final project capital hump w

  • public static const int A=1;这段代码有错误么?错了.常量不能标记为static 2013-04-09

    public static const int A=1;这段代码有错误么?错了.常量不能标记为static

  • [Transfer] C / C + + language to explore the deep void and void pointer 2010-10-22

    1. Overview many beginners on the C / C + + language in the void and the void pointer type do not understand, so in the use of some errors. This paper will be void explain the profound meaning of keywords and void and the void pointer type detailing

  • 深入理解void以及void指针的含义 2014-12-16

    本篇文章对小编void以及void指针的含义进行了详细的分析和介绍.需要的朋友参考下 void的含义void即"无类型",void *则为"无类型指针",可以指向任何数据类型. void指针使用规范①void指针可以指向任意类型的数据,亦即可用任意数据类型的指针对void指针赋值.例如: int *pint; void *pvoid; pvoid = pint; /* 不过不能 pint = pvoid; */ 如果要将pvoid赋给其他类型指针,则需要强制类型转换

  • void* mymemcpy( void* dest, const void* src, size_t count ) 2010-11-25

    void* mymemcpy( void* dest, const void* src, size_t count ) { assert(dest!=NULL); assert(src!=NULL); char* pdest=(char*)dest; char* psrc=(char*)src; if(psrc<pdest&&psrc+count>pdest) { psrc=psrc+count-1; pdest=pdest+count-1; while(count-->

  • void和void* 2013-02-16

    void的含义 void即"无类型",void *则为"无类型指针",可以指向任何数据类型. void指针使用规范 ①void指针可以指向任意类型的数据,亦即可用任意数据类型的指针对void指针赋值.例如: int *pint; void *pvoid; pvoid = pint; /* 不过不能 pint = pvoid; */ 如果要将pvoid赋给其他类型指针,则需要强制类型转换如:pint = (int *)pvoid; ②在ANSI C标准中,不允许对vo

  • void及void指针深层次探索 2013-04-26

    1.概述 许多初学者对C/C++语言中的void及void指针类型不甚理解,因此在使用上出现了一些错误.本文将对void关键字的深刻含义进行解说,并详述void及void指针类型的使用方法与技巧. 2.void的含义 void的字面意思是"无类型",void *则为"无类型指针",void *可以指向任何类型的数据. void几乎只有"注释"和限制程序的作用,因为从来没有人会定义一个void变量,让我们试着来定义: void a; 这行语句编译时

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.495 (s). 13 q(s)