Android ProgressDialog 載入進度

來源:互聯網
上載者:User

標籤:

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" > 5  6     <Button 7         android:layout_width="wrap_content" 8         android:layout_height="wrap_content" 9         android:onClick="progress"10         android:text="ProgressDialog" />11 12 </RelativeLayout>
 1 public class MainActivity extends Activity { 2  3     @Override 4     protected void onCreate(Bundle savedInstanceState) { 5         super.onCreate(savedInstanceState); 6         setContentView(R.layout.activity_main); 7     } 8      9     /**10      * ProgressDialog是AlertDialog類的子類,可以為一個未定義進度的任務顯示一個旋轉輪形狀的進度動畫,11      * 或者為一個指定進度的任務顯示一個進度條。它的用處非常廣泛,在每次使用者操作一個延遲的任務時,我們都必須以進度對話方塊的形式告訴使用者,12      * 否則使用者並不知道操作已經開始,可能會多次操作同一個任務,並有可能導致異常發生。13      * @param v14      */15 16     public void progress(View v){17         final ProgressDialog dialog = new ProgressDialog(this);18         dialog.setTitle("進度條對話方塊");19         dialog.setMessage("正在載入...");20         //dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//旋轉輪進度21         dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//水平載入進度條22         dialog.setMax(200);//預設值10023         dialog.show();24         new Thread(){25             public void run() {26                 int index = 0;27                 while(index++ < dialog.getMax()){28                     dialog.setProgress(index);29                     try {30                         Thread.sleep(100);31                     } catch (InterruptedException e) {32                         e.printStackTrace();33                     }34                 }35                 //載入完成關閉對話方塊36                 if(dialog!=null && dialog.isShowing()){37                     dialog.dismiss();38                 }39             }40         }.start();41     }42 }
MainActivity

 

Android ProgressDialog 載入進度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.