


public class AndroidsCastleActivity extends Activity implements Runnable {
private ProgressDialog _progressDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_progressDialog = new ProgressDialog(this);
_progressDialog.setTitle("レンダリング中");
_progressDialog.setMessage("しばらくお待ちください...");
_progressDialog.setIndeterminate(false); // 進捗が分かることを示す
_progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// プログレスバータイプ
_progressDialog.setMax(100); // 最大100にする
_progressDialog.show(); // 表示開始
Thread thread = new Thread(this);
thread.start();
}
public void run() {
for (int i = 0; i < 100; i++) {
handler.sendMessage(Message.obtain(handler, i)); // iをhandleMessageに送る
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
handler.sendMessage(Message.obtain(handler, -1));// -1なら終了の合図
}
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == -1) {// -1なら終了の合図
_progressDialog.dismiss(); // ダイアログの終了
return;
}
_progressDialog.setProgress(msg.what);// もらった値を進捗率にセットする
}
};
}

Portions of this page are modifications
based on work created and shared by Google and used according to terms
described in the Creative Commons 3.0 Attribution License.
- Remical Soft -