欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Android開發(fā)中ProgressDialog簡單用法示例

本文實例講述了Android開發(fā)中ProgressDialog簡單用法。分享給大家供大家參考,具體如下:

在海倫等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網站建設、成都網站制作 網站設計制作按需搭建網站,公司網站建設,企業(yè)網站建設,品牌網站制作,成都全網營銷,成都外貿網站制作,海倫網站建設費用合理。

網上一般對進度條的示例都是如何顯示,沒有在任務結束如何關閉的文章,參考其他文章經過試驗之后把整套進度條顯示的簡單示例如下:

建立android工程等工作都略去,Google一下就可以了。

下面來介紹主要的Activity

ProgressBarDemo.java

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;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    statusTextView = (TextView)findViewById(R.id.status);
    beginBtn = (Button)findViewById(R.id.beginBtn);
    setListener();
  }
  /**
   * 用Handler來更新UI
   */
  private Handler handler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
      //關閉ProgressDialog
      progressDialog.dismiss();
      //更新UI
      statusTextView.setText("Completed!");
    }};
  /**
   * 點擊按鈕事件listener
   */
  private void setListener(){
    beginBtn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        //顯示ProgressDialog
        progressDialog = ProgressDialog.show(ProgressBarDemo.this, "Loading...", "Please wait...", true, false);
        //新建線程
        new Thread(){
          @Override
          public void run() {
            //需要花時間計算的方法
            Calculation.calculate(4);
            //向handler發(fā)消息
            handler.sendEmptyMessage(0);
          }}.start();
      }
    });
  }
}

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;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    statusTextView = (TextView)findViewById(R.id.status);
    beginBtn = (Button)findViewById(R.id.beginBtn);
    setListener();
  }
  /**
   * 用Handler來更新UI
   */
  private Handler handler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
      //關閉ProgressDialog
      progressDialog.dismiss();
      //更新UI
      statusTextView.setText("Completed!");
    }};
  /**
   * 點擊按鈕事件listener
   */
  private void setListener(){
    beginBtn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        //顯示ProgressDialog
        progressDialog = ProgressDialog.show(ProgressBarDemo.this, "Loading...", "Please wait...", true, false);
        //新建線程
        new Thread(){
          @Override
          public void run() {
            //需要花時間計算的方法
            Calculation.calculate(4);
            //向handler發(fā)消息
            handler.sendEmptyMessage(0);
          }}.start();
      }
    });
  }
}

Calculation.java

package com.lveyo.android.demo.progressbar;
/**
 * 示意方法
 * @author lveyo
 *
 */
public class Calculation {
  public static void calculate(int sleepSeconds){
    try {
      Thread.sleep(sleepSeconds * 1000);
    } catch (Exception e) {
      // TODO: handle exception
    }
  }
}

package com.lveyo.android.demo.progressbar;
/**
 * 示意方法
 * @author lveyo
 *
 */
public class Calculation {
  public static void calculate(int sleepSeconds){
    try {
      Thread.sleep(sleepSeconds * 1000);
    } catch (Exception e) {
      // TODO: handle exception
    }
  }
}

main.xml文件

<?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:id="@+id/status"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/hello"
  />
<Button android:id="@+id/beginBtn"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="begin"
  />
</LinearLayout>

<?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:id="@+id/status"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/hello"
  />
<Button android:id="@+id/beginBtn"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="begin"
  />
</LinearLayout>

在android中,通常我們無法在單獨的線程中更新UI,而要在主線程中,這也就是為什么我們要使用 Handler了,當handler收到消息中,它會把它放入到隊列中等待執(zhí)行,通常來說這會很快被執(zhí)行。

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結》

希望本文所述對大家Android程序設計有所幫助。

分享文章:Android開發(fā)中ProgressDialog簡單用法示例
瀏覽地址:http://chinadenli.net/article6/ppsgog.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供網站內鏈響應式網站、網站制作移動網站建設、手機網站建設、企業(yè)網站制作

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都網頁設計公司
九九热精彩视频在线播放| 亚洲欧美天堂精品在线| 亚洲妇女作爱一区二区三区| 美国欧洲日本韩国二本道| 色婷婷丁香激情五月天| 中文字幕一区二区久久综合| 日本女优一区二区三区免费| 亚洲另类女同一二三区| 欧美一区二区在线日韩| 欧美色欧美亚洲日在线| 日本精品啪啪一区二区三区| 国产精品亚洲欧美一区麻豆| 欧美一级黄片免费视频| 99久热只有精品视频免费看| 色一情一乱一区二区三区码| 国产成人免费激情视频| 91后入中出内射在线| 亚洲精品一区二区三区免| 国产日产欧美精品视频| 国产一级特黄在线观看| 国产成人精品午夜福利av免费| 日韩人妻毛片中文字幕| 日韩精品综合福利在线观看| 中文字幕免费观看亚洲视频| 午夜福利网午夜福利网| 欧美精品亚洲精品一区| 欧美国产日韩在线综合| 久久精品国产熟女精品| 日本高清一区免费不卡| 国产主播精品福利午夜二区| 一区二区三区人妻在线| 色涩一区二区三区四区| 九九热精品视频免费在线播放| 韩国日本欧美国产三级| 日韩精品在线观看完整版| 久久福利视频这里有精品| 欧美夫妻性生活一区二区| 亚洲综合天堂一二三区| 色婷婷人妻av毛片一区二区三区| 日本高清中文精品在线不卡| 黑鬼糟蹋少妇资源在线观看|