• 【转】【Android】ProgressDialog进度条对话框的使用


    Android ProgressDialog进度条对话框的使用: 
    转自:http://aina-hk55hk.iteye.com/blog/679134/

    Java代码  收藏代码
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:orientation="vertical" android:layout_width="fill_parent"  
    4.     android:layout_height="fill_parent">  
    5.     <TextView android:layout_width="fill_parent"  
    6.         android:layout_height="wrap_content" android:text="@string/hello" />  
    7.     <Button android:text="圆形进度条" android:id="@+id/Button01"  
    8.         android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>  
    9.     <Button android:text="长型进度条" android:id="@+id/Button02"  
    10.         android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>  
    11.   
    12. </LinearLayout>  



    Java代码  收藏代码
      1. package com.Aina.Android;  
      2.   
      3. import android.app.Activity;  
      4. import android.app.ProgressDialog;  
      5. import android.content.DialogInterface;  
      6. import android.os.Bundle;  
      7. import android.view.View;  
      8. import android.view.View.OnClickListener;  
      9. import android.widget.Button;  
      10.   
      11. public class Test_ProgressDialog extends Activity {  
      12.     /** Called when the activity is first created. */  
      13.     private ProgressDialog mpDialog;  
      14.     private Button btn1,btn2;  
      15.     private int mCount = 0;  
      16.     @Override  
      17.     public void onCreate(Bundle savedInstanceState) {  
      18.         super.onCreate(savedInstanceState);  
      19.         setContentView(R.layout.main);  
      20.         btn1 = (Button) this.findViewById(R.id.Button01);  
      21.         btn2 = (Button) this.findViewById(R.id.Button02);  
      22.         btn1.setOnClickListener(new OnClickListener(){  
      23.   
      24.             @Override  
      25.             public void onClick(View v) {  
      26.                 mpDialog = new ProgressDialog(Test_ProgressDialog.this);  
      27.                 mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
      28.                 mpDialog.setTitle("提示");//设置标题  
      29.                 mpDialog.setIcon(R.drawable.icon);//设置图标  
      30.                 mpDialog.setMessage("这是一个圆形进度条");  
      31.                 mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
      32.                 mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
      33.                 mpDialog.setButton("确定"new DialogInterface.OnClickListener(){  
      34.   
      35.                     @Override  
      36.                     public void onClick(DialogInterface dialog, int which) {  
      37.                         dialog.cancel();  
      38.                           
      39.                     }  
      40.                       
      41.                 });  
      42.                 mpDialog.show();  
      43.             }  
      44.               
      45.         });  
      46.         btn2.setOnClickListener(new OnClickListener(){  
      47.   
      48.             @Override  
      49.             public void onClick(View v) {  
      50.                 mCount = 0;  
      51.                 mpDialog = new ProgressDialog(Test_ProgressDialog.this);  
      52.                 mpDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);  
      53.                 mpDialog.setTitle("提示");  
      54.                 mpDialog.setIcon(R.drawable.icon);  
      55.                 mpDialog.setMessage("这是一个长型进度条");  
      56.                 mpDialog.setMax(100);  
      57.                 mpDialog.setProgress(0);  
      58.                 mpDialog.setSecondaryProgress(50);  
      59.                 mpDialog.setIndeterminate(false);  
      60.                 mpDialog.setCancelable(true);  
      61.                 mpDialog.setButton("取消"new DialogInterface.OnClickListener(){  
      62.   
      63.                     @Override  
      64.                     public void onClick(DialogInterface dialog, int which) {  
      65.                         dialog.cancel();  
      66.                           
      67.                     }  
      68.                       
      69.                 });  
      70.                 new Thread(){  
      71.                     public void run(){  
      72.                         try{  
      73.                             while(mCount<=100){  
      74.                                 mpDialog.setProgress(mCount++);  
      75.                                 Thread.sleep(100);  
      76.                             }  
      77.                             mpDialog.cancel();  
      78.                         }catch(Exception ex){  
      79.                             mpDialog.cancel();  
      80.                         }  
      81.                     }  
      82.                 }.start();  
      83.                 mpDialog.show();  
      84.             }  
      85.               
      86.         });  
      87.   
      88.     }  
      89. }  
  • 相关阅读:
    onload事件addLoadEvent函数
    Struts 2读书笔记Struts 2知识总结
    oraclehttp://localhost:5560/isqlplus 打不开的解决方案
    Struts 2读书笔记拦截器之示例:使用拦截器完成权限控制
    使用定时器实现弹弹球
    Servlet过滤器大全
    java面试大全
    sql学习笔记
    java学习笔记
    JSP快速入门教程——全十讲
  • 原文地址:https://www.cnblogs.com/wangcan/p/3448846.html
Copyright © 2020-2023  润新知