Android - Hide all shown Toast Messages

crazyV picture crazyV · May 3, 2010 · Viewed 53.1k times · Source

How do I remove all toast messages currently displayed?

In my App, there is a list, when a user clicks on an item, a toast message is displayed, 10 items - 10 toast messages.

So if the user clicks 10 times, then presses the menu button, they have to wait for some seconds until they're able to read the menu option text.

It shouldn't be like that :)

Answer

Mudar picture Mudar · Dec 19, 2010

My solution was to initialize a single Toast in the activity. Then changing its text on each click.

Toast mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
if (a) {
  mToast.setText("This is a");
  mToast.show();
} else if (b) {
  mToast.setText("This is b");
  mToast.show();
}