注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

2011终点

2011终点

 
 
 

日志

 
 

ProgressDialog  

2012-01-27 15:28:08|  分类: Android学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

1.

package cn.wzg.activity;

import android.app.Activity; 
import android.app.ProgressDialog; 
import android.content.DialogInterface; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
 
public class Activity04Activity extends Activity { 
   /** Called when the activity is first created. */ 
     private ProgressDialog mpDialog;   
     private Button btn1,btn2;   
     private int mCount = 0; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
         
        btn1 = (Button) this.findViewById(R.id.Button01);   
        btn2 = (Button) this.findViewById(R.id.Button02);   
        btn1.setOnClickListener(new OnClickListener(){   
   
            @Override   
            public void onClick(View v) {   
                mpDialog = new ProgressDialog(Activity04Activity.this);   
                mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条   
                mpDialog.setTitle("提示");//设置标题   
                mpDialog.setIcon(R.drawable.ic_launcher);//设置图标   
                mpDialog.setMessage("程序赈灾安装中,请等待!");   
                mpDialog.setIndeterminate(false);//设置进度条是否为不明确   
                mpDialog.setCancelable(false);//设置进度条是否可以按退回键取消   
                mpDialog.setButton("确定", new DialogInterface.OnClickListener(){   
   
                    @Override   
                    public void onClick(DialogInterface dialog, int which) {   
                        dialog.cancel(); 
                                                   
                    }   
                       
                }); 
                mpDialog.show();   
            }   
               
        });   
        btn2.setOnClickListener(new OnClickListener(){   
   
            @Override   
            public void onClick(View v) {   
                mCount = 0;   
                mpDialog = new ProgressDialog(Activity04Activity.this);   
               mpDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);   
               mpDialog.setTitle("提示");   
                mpDialog.setIcon(R.drawable.ic_launcher);   
               mpDialog.setMessage("程序正在安装中,请等候!");   
                mpDialog.setMax(100);   
                mpDialog.setProgress(0);   
                mpDialog.setSecondaryProgress(20);   
               mpDialog.setIndeterminate(false);   
                mpDialog.setCancelable(false);   
                mpDialog.setButton("取消", new DialogInterface.OnClickListener(){   
   
                   @Override   
                   public void onClick(DialogInterface dialog, int which) {   
                       dialog.cancel();   
                          
                   }   
                       
                });   
               new Thread(){   
                    public void run(){   
                        try{   
                            while(mCount<=100){   
                                mpDialog.setProgress(mCount++);   
                               Thread.sleep(100);   
                            }   
                           mpDialog.cancel();   
                       }catch(Exception ex){   
                            mpDialog.cancel();   
                        }   
                    }   
                }.start();   
               mpDialog.show();   
           }   
               
        }); 
    } 

2.main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <Button
        android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="圆形进度条" >
    </Button>

    <Button
        android:id="@+id/Button02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="长型进度条" >
    </Button>

</LinearLayout>

 

3  结果:

ProgressDialog - lvjian118 - 2011终点
  评论这张
 
阅读(375)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017