我有许多按钮。而就点击他们每个人我告诉敬酒。但是,尽管举杯负载和秀看来,另一个按钮被点击,并致祝酒辞不显示,直到一个正在显示完成。
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(); }更多推荐
显示在同一时间多个举杯!问题
发布评论