Custom Toast Cancel not working

断了今生、忘了曾经 提交于 2019-12-03 07:52:21
Tomcat

I suffered from same issue (custom toast queuing up) and found a solution. It worked fine in my case.

Having custom toast object initially set to null.

  • If this is null, create new custom toast object with "new".

  • As far as you are in same activity, don't "new" to create new object. Instead, use that object. Since setText() won't work in this case, use setView() as you do with your custom toast.

  • With this way show(), cancel(), show(), cancel() worked exactly as I expect. No delay, no queuing.

Hope this helps.

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.

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

in above code toast.setDuration(Toast.LENGTH_LONG); in that u use toast.setDuration(Toast.LENGTH_SHORT); or se the particular time.Toast is cancelled automatically.we can't cancel it

Use this code for custom text:

LayoutInflater mInflater=LayoutInflater.from(context);
View view=mInflater.inflate(R.layout.tost_layout,null);
Toast toast=new Toast(this);
toast.setView(view);
toast.show();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!