我根据这个网站http://www.mkyong.com/android/android-progress-bar-example/进行了对话
当进度条达到 100% 时,对话框关闭,但吐司仍然持续出现。我注意到在 bar 达到 100% 之后,progressHandler 仍然循环运行。
我该如何解决这个问题?我想要的东西:当进度条达到 100% 时,对话框关闭,Toast 显示并关闭。
Thread background = new Thread(new Runnable() {
@SuppressWarnings("null")
public void run() {
try {
while (dialog.getProgress() <= dialog.getMax()) {
// wait 500ms between each update
Thread.sleep(100);
// active the update handler
progressHandler.sendMessage(progressHandler.obtainMessage());
}
} catch (java.lang.InterruptedException e) {
// if something fails do something smart
Toast.makeText(getApplicationContext(), "Error Occurs",Toast.LENGTH_LONG).show();
}
}
});
// start the background thread
background.start();
}
// handler for the background updating
Handler progressHandler = new Handler() {
public void handleMessage(Message msg) {
dialog.incrementProgressBy(increment);
if(dialog.getProgress()==100){
editor.putInt("lastestSummaryNoSent",summary.getCurrentSummaryNo());
editor.commit();
dialog.dismiss();
Toast.makeText(getApplicationContext(), "Update Finished", Toast.LENGTH_LONG).show();
}
}
};