I am having a problem updating the progress bar. I am updating the progress bar in a separate thread and a variable in which the progressbar progress depends (which is a class variable), updating in another thread. Thus, the execution dialog shows, but always 0%, without updating it. Help me please.
public void setProgressbar() { progressBar = new ProgressDialog(context); progressBar.setCancelable(true); progressBar.setMessage("File downloading ..."); progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressBar.setProgress(0); progressBar.setMax(100); progressBar.show(); Thread thread = new Thread() { public void run() { while(progressBar.getProgress() < 100) { Log.v("progressbar", getProgress()+""); progressBar.setProgress(getProgress()); try { Thread.sleep(2000); } catch (InterruptedException e) {
Refresh Value Code
Thread thread = new Thread() { public void run() { . . . while((bytesRead = is.read(bytearray, 0, bytearray.length)) != -1) { bos.write(bytearray, 0, bytesRead); totaldownload = totaldownload + bytesRead; Log.v("downloadign ", totaldownload+"");
And the getPrgoress method
public int getProgress() { return (int) ((totaldownload/sizeoffile) * 100); }
source share