简体   繁体   中英

Android horizontal progressBar not updating progress

I am using facebook graph request for uplaoding video. This api has onProgressCallback method which gives current bytes written and maximum bytes that can be written for a file as follows:

@Override
public void onProgress(final long current, final long max) {
    if (isFirstLoad) {
        progressBarHorizonatl.setProgress(0);
        progressBarHorizonatl.setMax((int) max);
        isFirstLoad = false;
    }
    progressBarHorizontal.setProgress((int) current);
}

this method is called repeatedly while uploading the video but progress bar is not updated. It will get updated at the last call only. Can anyone help me what might be the problem.

Update ProgressBar on UI thread. Try attached code.

@Override
public void onProgress(final long current, final long max) {
    if (isFirstLoad) {
        progressBarHorizonatl.setProgress(0);
        progressBarHorizonatl.setMax((int) max);
        isFirstLoad = false;
    }
    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            Log.d("UI thread", "I am the UI thread");
                            progressBarHorizontal.setProgress((int) current);
                        }
                    });

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM