Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display two Toast messages at once?

I would like one Toast message to display in one location and a different Toast message to display in another location simultaneously.

  1. Multiple Toast messages seem to always queue and display in order. Is it possible to show both messages at the same time?

  2. Is there a workaround that at least gives that appearance and doesn't involve messing with the activity layout?

Edit: It seems the answer to the first question is no, it's not possible. How about a workaround? A solution for me would include something that appears "over" the app like a Toast and doesn't interfere with user interaction with the app (so, not an AlertDialogue or anything that calls onPause() etc.).

like image 623
gotube Avatar asked Mar 23 '14 17:03

gotube


People also ask

What is the difference between toast and notification?

A toast is a small display on the bottom of the screen. A notification is displayed in the top menu bar. Save this answer.

Where do you show toast messages?

To initiate a Toast object, the ```makeText()``` method is used. Here you should mention the application context, content of the message, and the duration of the toast message. To display the Toast message, you can use the method ```show()```. An example code is given below.


2 Answers

As Jay Patel said, it cannot be done. But there IS workaround! You can create custom Toast which can contain any View. That means you can have layout with two messages on different places inside one toast.

You can find how to do that here, or you can start directly with this snippet:

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
                           (ViewGroup) findViewById(R.id.toast_layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("This is a custom toast");

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
like image 113
Firzen Avatar answered Sep 20 '22 21:09

Firzen


Short answer, No you can't

You can not show 2 Toast at the same time. i am sure about this, i already tried, but i can display only one Toast.

But if you want to really display two toasts at the same time then you will set thread mechanism to shown one after another in the same place.

like image 42
Jaykumar Patel Avatar answered Sep 18 '22 21:09

Jaykumar Patel