Android:是否会延迟烤面包的显示? [英] Android: Adding a delay to the display of toast?
本文介绍了Android:是否会延迟烤面包的显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果某个条件为 true
或 false
,我希望显示 toast
.但是,我希望此烤面包在显示之前先延迟两秒钟
.
I wish to display a toast
if a certain condition is true
or false
. However I want this toast to delay
for two seconds
before it is displayed.
我该怎么做?
当前的if语句:
if (result.equals("true")) {
loginDataBaseAdapter.updateUploadedRecord(sessionId);
Toast.makeText(MathsGameResults.this,
"Data is successfully uploaded.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(
MathsGameResults.this,
"Error while uploading. Please try again later.",
Toast.LENGTH_LONG).show();
}
}
推荐答案
尝试一下..
使用 Handler
// Handler which will run after 2 seconds.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(MathsGameResults.this,
"Data is successfully uploaded.",
Toast.LENGTH_LONG).show();
}
}, 2000);
这篇关于Android:是否会延迟烤面包的显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文