gpt4 book ai didi

java - 如何每 2 秒更改一次 ProgressDialog 的消息?

转载 作者:搜寻专家 更新时间:2023-11-01 08:24:02 26 4
gpt4 key购买 nike

我有 ProgressDialog,我想每 2 秒更改一次消息。在此代码中,我将进度时间设置为 10 秒。所以我想让它有 5 条消息

private void showProgressDialog() {

progressDialog = new ProgressDialog(this, getProgressDailogStyle());
progressDialog.setMessage("Processing ...");
progressDialog.show();
progressDialog.setCancelable(false);

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
progressDialog.dismiss();
mInterstitialAd.show();
}
}, 10000);
}

最佳答案

您可以使用 CountDownTimer

    count = 0;
progressDialog = new ProgressDialog(this, getProgressDailogStyle());
progressDialog.setMessage("Processing ...");
progressDialog.show();
progressDialog.setCancelable(false);

new CountDownTimer(10000, 2000) {

public void onTick(long millisUntilFinished) {
//here you can have your logic to set message
count=count+1;
if (count==1){
progressDialog.setMessage("Processing 1");
}else if (count==2){
progressDialog.setMessage("Processing 2");
}
// until the count = 5


}

public void onFinish() {
//the progress is finish
count = 0;
progressDialog.dismiss();

}

}.start();

关于java - 如何每 2 秒更改一次 ProgressDialog 的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47195081/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com