是否可以等到 toast 完成后再恢复该方法?
在我的一种方法中,如果用户提供正确的输入,就会出现一个 toast
。但是,我不希望在吐司完成之前显示下一张图像。
如果我使用 Thread.sleep(3000) ,则不允许在 UI 活动处于睡眠状态时显示 toast。
我正在尝试做的一个例子:
public void correction(){
if(correctionBoolean == true){
Toast.makeText(this, "Correct!", Toast.LENGTH_SHORT).show();
if(Toast.time == finished){
NextImage();}
}
In one of my methods, I have a toast
that appears if the user gives the correct input. However, I do not want the next image to display until the toast has finished.
If I use Thread.sleep(3000)
if does not allow the toast
to show as the UI activity is asleep.
An example of what I am trying to do:
public void correction(){
if(correctionBoolean == true){
Toast.makeText(this, "Correct!", Toast.LENGTH_SHORT).show();
if(Toast.time == finished){
NextImage();}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不相信有任何方法可以通过祝酒来做到这一点。如果您只是想向某人显示“您是正确的”窗口,我会考虑简单地使用带有单个“确定”按钮的 AlertDialog。
甚至可以显示一个没有按钮的对话框,让非 UI 线程休眠一会儿,然后关闭该对话框。
I don't believe there would be any way to do this with a toast. If you are simply trying to show someone a "You're Correct" Window, I would consider simply using an AlertDialog with a single positive Okay button.
It would even be possible to show a dialog with no buttons, have a non-UI thread sleep for a bit and then dismiss the dialog.
创建一个没有按钮的自定义对话框,并使用处理程序在短时间内将其关闭,然后显示下一个图像。
Create a custom dialog with no buttons and use a handler to both dismiss it after a short time and then show the next image.
将
CountDownTimer
与Toast 结合使用.LENGTH_SHORT
作为时间?Use a
CountDownTimer
withToast.LENGTH_SHORT
as the time?