显示在同一时间多个举杯!问题 [英] Showing multiple toast at the same time ! problem

查看:146
本文介绍了显示在同一时间多个举杯!问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆