Android-Fortschrittsbalken wird nicht aktualisiert
Ich habe ein Problem beim Aktualisieren des Fortschrittsbalkens. Ich aktualisiere die Fortschrittsanzeige in einem separaten Thread und die Variable, von der der Fortschritt der Fortschrittsanzeige abhängt (das ist eine Klassenvariable), die in einem anderen Thread aktualisiert wird. Der Fortschrittsdialog zeigt also immer 0%, ohne den Fortschritt zu aktualisieren. Hilf mir bitte.
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) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
thread.start();
Wertcode aktualisieren
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+"");
// progressBar.setProgress((int) ((totaldownload/sizeoffile) * 100));
}
bos.close();
.
.
.
};
thread.start()
Und getPrgoress-Methode
public int getProgress()
{
return (int) ((totaldownload/sizeoffile) * 100);
}