Home » Android » android – how to check if the toast have dismissed or not

android – how to check if the toast have dismissed or not

Posted by: admin May 14, 2020 Leave a comment

Questions:

i want to check if the toast have dismissed or not ,because user click the mouse the toast is show,but may me the user continuous click,so i need to check,i cannot use the dialog

How to&Answers:
Toast toast = null;
if (toast == null || toast.getView().getWindowVisibility() != View.VISIBLE) {
    toast = Toast.makeText(getApplicationContext(),
        "Text", Toast.LENGTH_SHORT);
    toast.show();
}

Check if the toast is visible before you show it again.

Answer:

Toast toast = yourToastCreationCode();

if (null == toast.getView().getWindowToken())
{
    yeahToastIsInvisible();
}

Answer:

Based on Denis answer, but worked better for me.

Toast t;
t=Toast.makeText(getActivity(), "test", Toast.LENGTH_LONG);
t.show;

if (t.getView().isShown())
{
   //visible
}