0
我讓基於這個網站http://www.mkyong.com/android/android-progress-bar-example/安卓:不能停止處理器運行時進度條對話框
當進度條達到100%,對話框關閉,但敬酒仍不斷出現在一個對話框。我注意到,在酒吧進入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();
}
}
};
感謝您的回答。順便說一句,這是我對這個問題的錯誤。更正的問題是我的代碼沒有任何錯誤,它可以在模擬器上運行。所以,我已經刪除了錯誤描述。對不起,我的錯誤,但非常感謝您的幫助:) –