when I download file i want progressbar sync with this. but not, my code is:
Thread thread = new Thread() {
public void run() {
try {
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
//add the data in the buffer to the file in the file output stream (the file on the sd card
fileOutput.write(buffer, 0, bufferLength);
//add up the size so we know how much is downloaded
downloadedSize += bufferLength;
pbar.setProgress((downloadedSize/totalSize)*100);
pbar.refreshDrawableState();
Log.d("CURRENT:", "" + (downloadedSize/totalSize)*100);
}
} catch (Exception ex) {
}
}
};
thread.start();
Also my catlog file is not updated. Any help please….
You cannot update the UI from a background thread, Use
AsyncTaskbecause Androiders call it painless threadingHere is a nice Tutorial for using
ProgressBarusingAsyncTask