Android アプリケーションのプログレス バーを作成するための支援を受けています。ここにたくさんの助けがあります!私は修正するのに苦労しているという問題を抱えています。アプリケーションがネットワーク接続されたコンピューターからファイルをダウンロードしようとしている間、進行状況バーが表示されます。これは問題なく動作しますが、エラーが発生した場合に備えて UI を更新する必要があります。スレッド内で UI を更新できず、getRaceResultsHandler から UI を更新したい。残念ながら、スレッドが完了する前にそのコードを実行します。私は運がないことをいくつか試しました。誰かが助けてくれるなら、以下にコメント付きのコードサンプルがあります。
public void getRaceResultsHandler (View view) {
dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setMessage("Attempting to transfer race files. Please wait...");
// Set progress style to spinner
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// display the progressbar
dialog.show();
// create a thread for downloading the files
Thread background = new Thread (new Runnable() {
public void run() {
//The Code here to execute the file download from the networked computer....
//Dismiss the progress bar because the download is either completed or failed...
dialog.dismiss();
}
});
// start the background thread
background.start();
//All Other Code Goes here to update the UI. Shows either an error message or a success based on the results of the download.
//My problem is that this code executes before the background thread is completed. I need it to wait until the thread is completed.
}