Display two Toast messages at once?
Asked Answered
M

2

10

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

Mantle answered 23/3, 2014 at 17:27 Comment(6)
Is it possible to show both messages at the same time? NOHarshman
It would probably not be the best user experience anyway to show them both at the same timePatman
Unless you are Cross-Eyed Mary... or a ChameleonHarshman
The app is designed to be used while the device is flat on a surface surrounded by users. The two messages have the same words, but one is at the bottom and the other is umop apisdn at the top so people looking at the app from the another angle can easily read it too.Mantle
"Is it possible to show both messages at the same time? NO" This is not true anymore. Maybe the API in 2014 did not allow it however the reverse appears to be true by default now.Exuviae
@francogrex Could you explain how it's done now? The API doesn't appear much different to 2014Mantle
A
9

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();
Adularia answered 27/6, 2015 at 1:46 Comment(1)
This works for now, but the setView() method was deprecated in API level 30.Reduplication
C
2

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.

Callas answered 23/3, 2014 at 17:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.