您好,登錄后才能下訂單哦!
package com.example.testprogress; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.annotation.SuppressLint; import android.app.Activity; import android.app.ProgressDialog; @SuppressLint("HandlerLeak") public class MainActivity extends Activity { private ProgressDialog progressDialog = null; private boolean flag = true; private int count = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); progressDialog = new ProgressDialog(this); progressDialog.setMessage("數據獲取中..."); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setCancelable(false);//是否可以被返回鍵取消 progressDialog.show(); for(int i=0; i<100; i++){ new Thread(mRunnable).start(); } } private Runnable mRunnable = new Runnable(){ @Override public void run() { while(flag){ try { Thread.sleep(1000); count ++; mHandler.sendMessage(mHandler.obtainMessage()); } catch (InterruptedException e) { e.printStackTrace(); } } } }; private Handler mHandler = new Handler(){ public void handleMessage(Message msg){ Log.v("article", Thread.currentThread().getId()+""); if(count >= 4){ flag = false; progressDialog.dismiss(); } } }; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。