【发布时间】:2021-12-24 10:35:08
【问题描述】:
我只想在progressStatus达到100时显示我的toast消息。为什么它执行了两次?感谢您的友好回复。
new Thread(new Runnable() {
@Override
public void run() {
while (progressStatus < 100) {
// Update the progress status
progressStatus += 1;
// Try to sleep the thread for 50 milliseconds
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.post(new Runnable(){
@Override
public void run() {
pb = dialog.findViewById(R.id.no_connectiondProgressBar);
pb.setProgress(progressStatus);
if (progressStatus == 100) {
final Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
View custom_view = getLayoutInflater().inflate(R.layout.custom_toast, null);
toast.setView(custom_view);
toast.show();
dialog.dismiss();
}
}
});
}
}
})
【问题讨论】:
标签: java android android-toast