【轉】Android ProgressDialog的使用2

來源:互聯網
上載者:User

標籤:

原文網址:http://www.cnblogs.com/hnrainll/archive/2012/03/28/2420908.html

 

<?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="fill_parent"     android:layout_height="fill_parent">      <TextView android:layout_width="fill_parent"         android:layout_height="wrap_content" android:text="@string/hello" />      <Button android:text="圓形進度條" android:id="@+id/Button01"         android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>      <Button android:text="長型進度條" android:id="@+id/Button02"         android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>     </LinearLayout> 

  

package com.Aina.Android;  

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 Test_ProgressDialog 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(Test_ProgressDialog.this);
mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//設定風格為圓形進度條
mpDialog.setTitle("提示");//設定標題
mpDialog.setIcon(R.drawable.icon);//設定表徵圖
mpDialog.setMessage("這是一個圓形進度條");
mpDialog.setIndeterminate(false);//設定進度條是否為不明確
mpDialog.setCancelable(true);//設定進度條是否可以按退回鍵取消
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(Test_ProgressDialog.this);
mpDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mpDialog.setTitle("提示");
mpDialog.setIcon(R.drawable.icon);
mpDialog.setMessage("這是一個長型進度條");
mpDialog.setMax(100);
mpDialog.setProgress(0);
mpDialog.setSecondaryProgress(50);
mpDialog.setIndeterminate(false);
mpDialog.setCancelable(true);
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();
}

});

}
}

【轉】Android ProgressDialog的使用2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.