显示在同一时间多个举杯!问题

编程入门 行业动态 更新时间:2024-10-12 18:19:22
本文介绍了显示在同一时间多个举杯!问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有许多按钮。而就点击他们每个人我告诉敬酒。但是,尽管举杯负载和秀看来,另一个按钮被点击,并致祝酒辞不​​显示,直到一个正在显示完成。

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(); }

更多推荐

显示在同一时间多个举杯!问题

本文发布于:2023-11-24 00:26:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623307.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   时间   在同一

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!