自定义吐司取消不工作 [英] Custom Toast Cancel not working

查看:151
本文介绍了自定义吐司取消不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了一些关于取消土司问题。他们没有一个是工作。

I have seen a number of questions on cancelling toast. None of them is working.

我有一个自定义的吐司。在code因为这是所有,但一条线一样的http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView

I have a custom Toast. The code for that is all but one line same as http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView

的差别是如下。

  1. 在祝酒变量定义为类变量
  2. 在整个Java code被写入的方法。
  3. 在此方法的开始,我已经添加了以下行取消敬酒。

  1. The toast variable is defined as a class variable
  2. The entire java code is written in a method.
  3. In the start of this method, I have added the following line to cancel the toast.

if (toast!=null){
    toast.cancel();
}

该方法被调用,当用户选择(的onClick)视图/布局。问题是,当用户选择了几声,面包会得到排队(该toast.cancel不工作)。

The method is called when user selects (onClick) the view/layout. The issue is when the user selects few times, the toast will get queued up (the toast.cancel is not working).

任何解决方案?

[更新] 我试图使敬酒对象的静态变量。仍然没有工作。

[update] I tried making toast object a static variable. Still dont work.

推荐答案

在最后,我创建了一个自定义对话框,使用户从做任何事情都要阻止(并避免多次敬酒弹出)。增加了的onClick监听事件在用户点击相同关闭对话框。

In the end, I created a Custom Dialog so that the user is blocked from doing anything else (and avoids multiple toasts popping up). Added a onClick Listener Event to close the dialog when user clicks the same.

悲的是Toast.cancel()无法正常工作。

Sad that Toast.cancel() doesn't work.

这篇关于自定义吐司取消不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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