我看到很多关于取消Toast的问题,但它们都不起作用。
我有一个自定义的Toast。该代码与http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView中的所有行都相同,除了一行。
区别如下:
- The toast variable is defined as a class variable
- The entire java code is written in a method.
In the start of this method, I have added the following line to cancel the toast.
if (toast!=null){ toast.cancel(); }
当用户选择(onClick)视图/布局时,会调用该方法。问题在于当用户选择几次时,Toast将被排队(toast.cancel无法工作)。
有什么解决方案吗?
[更新] 我尝试将Toast对象设置为静态变量。仍然不起作用。