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);
}
};
これは私がどこかから取った上記のコードです...このコードが言うように、プログレスバーを実行し続けるために、実際のコードをtryの下に保持する必要があります..私のコードは、ネストされたforループで構成される非常に長いコードです(これらすべてのビットとバイトを含むファイル全体を解析する) ..セクションのその部分で長いプロセスを維持する場合、タスクが完了するまで進行状況バーを更新するにはどうすればよいですか? いくつかの概念がありませんか?プロセスを実行し続け、進行状況バーを更新する方法を教えてください。