Update-Fortschritt auf Fortschritt-dialog von AsyncTask kann nicht bauen
Kann ich nicht bauen, mein Projekt, denn eclipse gibt Fehler
Hier ist die Schaltfläche click-Ereignis, der download wird gestartet
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog mProgressDialog;
mProgressDialog = new ProgressDialog(Test.this);
mProgressDialog.setMessage("Pobieranie");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
DownloadFile downloadFile = new DownloadFile();
downloadFile.execute("http://google.com");
}
});
and AsyncTask-Funktion
private class DownloadFile extends AsyncTask<String, Integer, String> {
[...]
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog.show(); //Here eclipse tell that "mProgressDialog cannot be resolved"
}
@Override
protected void onProgressUpdate(Integer... progress) {
super.onProgressUpdate(progress);
mProgressDialog.setProgress(progress[0]); //Here eclipse tell that "mProgressDialog cannot be resolved"
}
}
So, wo sollte ich code einfügen, der das erstellen meiner Dialogfeld mit dem Fortschritt?
Nur eine Anmerkung: Sie sind nicht erlaubt zu ändern, UI-von einem zweiten thread - Sie können nur so tun, aus dem Haupt-thread (UI-thread). Der zweite thread hat zu sagen, der Haupt-thread was zu änderung in der Benutzeroberfläche.
InformationsquelleAutor darkanzali | 2013-07-24
Du musst angemeldet sein, um einen Kommentar abzugeben.
InformationsquelleAutor koutuk
Du erroniously erstellen der ProgressDialog im Rahmen der OnClickListener.
Versuchen, die Erklärung der mProgressDialog an eine private member-variable der Aktivität/Fragment statt und nur instanziieren der ProgressDialog aus dem OnClickListener.
Prost!
InformationsquelleAutor mach
"Dieser code funktioniert gut für das herunterladen von Daten aus dem web"
InformationsquelleAutor baswaraj