gpt4 book ai didi

Android ProgressBar 不更新 onProgress

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:59:08 25 4
gpt4 key购买 nike

进度条不更新。然而,它在任务完成时结束。

int totalSms = 12;
int currentSms = 0;

public class ProgressTask extends AsyncTask<String, Integer, Boolean> {

/** progress dialog to show user that the backup is processing. */
private ProgressDialog dialog;

public ProgressTask(ScanInboxActivity activity) {
dialog = new ProgressDialog(activity);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMax(totalSms);
}

protected void onPreExecute() {
dialog.setMessage("Scan start");
dialog.show();
}

@Override
protected void onProgressUpdate(Integer... values) {
Log.d(TAG, "in onProgressUpdate: " + values[0]); // shows actuall count in the log
dialog.setProgress(values[0]); // does not update

//tried even this, does not work
//dialog.incrementProgressBy(values[0]);
}

@Override
protected void onPostExecute(final Boolean success) {
if (dialog.isShowing()) {
dialog.dismiss();
}
populateList();
}

protected Boolean doInBackground(final String... args) {
try {
Context context = getApplicationContext();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
while (currentSms < totalSms) {
Thread.sleep(1000);
currentSms++;
publishProgress(currentSms);
}
} catch (IllegalArgumentException e) {
} catch (InterruptedException e) {

}
return true;
}

最佳答案

dialog.setIndeterminate(true);

应该是false,否则加载值不会被计算

关于Android ProgressBar 不更新 onProgress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17166250/

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