當我使用下面的代碼在按鈕的點擊方法中創建了一個進度條。但點擊按鈕後需要2-3秒才能顯示進度條,以減少延遲時間以啓動進度條。減少顯示進度條的延遲
public void getProgressBar() {
progressBar = new ProgressDialog(this);
progressBar.setCancelable(true);
progressBar.setMessage("Loading...");
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.show();
progressBarStatus = 0;
new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {
progressBarStatus = doSomeTasks();////I am loading service
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}
if (progressBarStatus >= 100) {
progressBar.dismiss();
startActivity(new Intent(getApplicationContext(),
StatisticDisplay.class));
}
}
}).start();
}
鏈接已損壞。 – Kedar 2016-04-28 18:57:58
@Kedar那不是我的錯。 – 2016-04-29 06:31:22