首页 > 代码库 > ProgressBar

ProgressBar

package com.example.myprogressbar;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.ProgressBar;public class MainActivity extends Activity {    ProgressBar progressBar1 ;    /*long startTime =TimeUtil.timeToLong("2014-8-8 00:05:00")/1000;    long endTime =TimeUtil.timeToLong("2014-8-8 00:06:00")/1000;*/    Thread thread;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);        progressBar1.setProgress(0);        Log.d("hefen", "time ==");         thread =new Thread(new Runnable() {            long currentTime = System.currentTimeMillis()/1000;                @Override            public void run() {                int progressBarMax =100;                    while(progressBarMax!= progressBar1.getProgress()){                        int stepProgress = 0;                        int currentProgress = progressBar1.getProgress();                        stepProgress++;                        int currentTime = 100;                        int startTime =200;                        if(currentTime<=200){                            currentTime+=10;                                                    }                        progressBar1.setProgress(currentProgress+stepProgress);                        Log.d("hefen", currentProgress+stepProgress+"");                        try {                            Thread.sleep(1000);                        } catch (InterruptedException e) {                            e.printStackTrace();                        }                                            }                        progressBar1.setProgress(0);                            }        });        thread.start();    }    @Override    protected void onPause() {        // TODO Auto-generated method stub        super.onPause();        thread.stop();    }    }