页面上现有ProgressBar控件progressBar,请用书写线程以10秒的的时间完成其进度显示工作

public class ProgressBarStu extends Activity {


private ProgressBar progressBar = null;


protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);


setContentView(R.layout.progressbar);


//
从这到下是关键


progressBar = (ProgressBar)findViewById(R.id.progressBar);



Thread thread = new Thread(new Runnable() {



@Override


public void run() {


int progressBarMax = progressBar.getMax();


try {


while(progressBarMax!=progressBar.getProgress())


{



int stepProgress = progressBarMax/10;


int currentprogress = progressBar.getProgress();


progressBar.setProgress(currentprogress+stepProgress);


Thread.sleep(1000);


}



} catch (InterruptedException e) {


// TODO Auto-generated catch block


e.printStackTrace();


}



}


});



thread.start();


//
关键结束


}


}

你可能感兴趣的:(页面上现有ProgressBar控件progressBar,请用书写线程以10秒的的时间完成其进度显示工作)