Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

Android - Hide all shown Toast Messages

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...