标签:
1 public class MyActivity extends Activity { 2 private static final int PROGRESS = 0x1; 3 4 private ProgressBar mProgress; 5 private int mProgressStatus = 0; 6 7 private Handler mHandler = new Handler(); 8 9 protected void onCreate(Bundle icicle) { 10 super.onCreate(icicle); 11 12 setContentView(R.layout.progressbar_activity); 13 14 mProgress = (ProgressBar) findViewById(R.id.progress_bar); 15 16 // Start lengthy operation in a background thread 17 new Thread(new Runnable() { 18 public void run() { 19 while (mProgressStatus < 100) { 20 mProgressStatus = doWork(); 21 22 // Update the progress bar 23 mHandler.post(new Runnable() { 24 public void run() { 25 mProgress.setProgress(mProgressStatus); 26 } 27 }); 28 } 29 } 30 }).start(); 31 } 32 }
标签:
原文地址:http://www.cnblogs.com/lya-nju/p/4246551.html