アンドロイドのプログレスバーに関する疑問があります。これは私がから取った上記のコード..ですAndroidプログレスバーの作業について
dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setMessage("Loading...");
// set the progress to be horizontal
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// reset the bar to the default value of 0
dialog.setProgress(0);
// get the maximum value
EditText max = (EditText) findViewById(R.id.maximum);
// convert the text value to a integer
int maximum = Integer.parseInt(max.getText().toString());
// set the maximum value
dialog.setMax(maximum);
// display the progressbar
dialog.show();
// create a thread for updating the progress bar
Thread background = new Thread (new Runnable() {
public void run() {
try {
// enter the code to be run while displaying the progressbar.
//
// This example is just going to increment the progress bar:
// So keep running until the progress value reaches maximum value
while (dialog.getProgress()<= dialog.getMax()) {
// wait 500ms between each update
Thread.sleep(500);
// active the update handler
progressHandler.sendMessage(progressHandler.obtainMessage());
}
} catch (java.lang.InterruptedException e) {
// if something fails do something smart
}
}
});
// start the background thread
background.start();
}
// handler for the background updating
Handler progressHandler = new Handler() {
public void handleMessage(Message msg) {
dialog.incrementProgressBy(increment);
}
};
を私はそれを実装していない、まだなく、期限の不足に私は私が良く起こるために何が起こっているかと、なぜ明確に実装したときに確認しますどこかに...このコードでは、私は実際のコードを以下のようにしてプログレスバーを実行し続けるようにしなければならないと言います。私の疑問は、私のコードは非常に長いもので、ネストされたforループおよびバイト)..私はセクションのその部分で私の長いプロセスを維持する場合、どのようにタスクを完了するまで、進行状況バーを更新できますか? 私はいくつかの概念を欠いていますか?どうすれば私のプロセスを実行し続けることができますか、プログレスバーを更新することができますか?
そのため、そのセクションにループを入れ子にしておくと、プログレスバーが複数のスレッドの原因を更新し続けるのでしょうか? – Tani
別のスレッドで作業をしているので、アニメーションが残っているはずです。しかし、ネストされたループのどこかで進捗ハンドラを介してメインスレッドに進捗状況を伝える必要があります。 – Heinrisch