显示在同一时间多个举杯!问题 [英] Showing multiple toast at the same time ! problem
问题描述
我有许多按钮。而就点击他们每个人我告诉敬酒。但是,尽管举杯负载和秀看来,另一个按钮被点击,并致祝酒辞不显示,直到一个正在显示完成。
I have many buttons. And on click of each of them I show a Toast. But while a toast loads and show in view, another button is clicked and the toast is not displayed until the one that is being displayed finishes.
所以,我想一种方法来检测,如果敬酒是显示在当前的背景下理清。有没有办法知道是否正在显示,这样我可以取消它,并显示一个新的敬酒。
So, I would like to sort out a way to detect if a toast is showing in the current context. Is there a way to know if a toast is being displayed such that I can cancel it and display a new one.
推荐答案
您可以缓存在活动的可变电流吐司
,然后只是显示下一个敬酒之前取消。下面是一个例子:
You can cache current Toast
in Activity's variable, and then cancel it just before showing next toast. Here is an example:
Toast m_currentToast;
void showToast(String text)
{
if(m_currentToast != null)
{
m_currentToast.cancel();
}
m_currentToast = Toast.makeText(this, text, Toast.LENGTH_LONG);
m_currentToast.show();
}
另一种方式来即时更新吐司
消息:
Another way to instantly update Toast
message:
void showToast(String text)
{
if(m_currentToast == null)
{
m_currentToast = Toast.makeText(this, text, Toast.LENGTH_LONG);
}
m_currentToast.setText(text);
m_currentToast.setDuration(Toast.LENGTH_LONG);
m_currentToast.show();
}
这篇关于显示在同一时间多个举杯!问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!