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
Asked
Active
Viewed 1.4k times
3 Answers
17
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.

Ginsan
- 344
- 2
- 8
-
1Showing toast `getWindowVisibility` returns `View.GONE` (6.0.1) – Konstantin Konopko May 23 '16 at 15:15
8
Toast toast = yourToastCreationCode();
if (null == toast.getView().getWindowToken())
{
yeahToastIsInvisible();
}

Denis Gladkiy
- 2,084
- 1
- 26
- 40
-
1noe .. it will still be null if toast is created.. cant check visibility – stinepike Apr 20 '13 at 05:10
5
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
}

stalker
- 55
- 1
- 2
-
-
According to the documentation isShown() "Returns the visibility of this view and all of its ancestors" So this is not working – hushed_voice Sep 20 '17 at 13:10