Questions tagged [android-toast]

A Toast is a momentary popup in Android which provides simple feedback about an operation.

Summary

A Toast is a momentary popup which provides simple feedback about an operation1. Toasts are added to an application's WindowManager and are not bound to an activity's UI; therefore, a Toast can remain visible after an Activity is navigated away from.

Toasts are typically displayed by using the makeText() method:

   // also supports Toast.LENGTH_LONG
Toast.makeText(getApplicationContext(), "some message", Toast.LENGTH_SHORT).show();

Sample Toast:-

enter image description here

It is important to note that the duration parameter requires either the LENGTH_LONG or LENGTH_SHORT . A custom millisecond value is not a valid duration parameter.

Custom Toasts

Toasts can use a custom View by using the setView() method3.

Usage

Toast messages should be as unobtrusive as possible4. Toasts should be used in situations that necessitate the user to be notified of certain background tasks such as a setting or draft being saved. Generally, Toasts should not exceed a single line of text.

Further reading

Toast overview

Toast developer guide

Toast code

Image Source and Brief guide

References:

1http://developer.android.com/guide/topics/ui/notifiers/toasts.html [Accessed on March 10, 2015]

2http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.2_r1/android/widget/Toast.java#Toast.0LENGTH_SHORT [Accessed on March 10, 2015]

3http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView [Accessed on March 10, 2015]

4http://developer.android.com/reference/android/widget/Toast.html [Accessed on March 10, 2015]

639 questions
-2
votes
2 answers

How to replace Toast message by Intent in below code?

This is the code in which I want to change this one Toast message into 3 Intent. How can I do so: @Override public void onClick(int buttonIndex) { Toast.makeText( parent.getContext(), "On click " +…
Anish
  • 1
  • 3
-2
votes
2 answers

Making toast from alert dialog positive Button

I want the alert dialog when clicking on the positive button to show toast, but instead, It shows an erorr! the code AlertDialog.Builder builder = new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) …
-2
votes
1 answer

Android Quiz If-Else Statements and Toasts

The java code is what I have so far in Android Studio, as part of a multiple choice quiz app I am developing. I want to create a toast that is shown when a button is clicked. As of now I have the following code. Depending on whether the correct…
astonky
  • 1
  • 2
-2
votes
2 answers

Context Argument in Toast.maketext()

this is my first post here. I used the search function and could not find a complete answer,so I hope this is not a redundant question. I should note that I m really new to coding so maybe I did find an answer but did not realise it. I have been…
-2
votes
3 answers

Toast from spinner not showing

The spinner has an array list of band genres when selecting any of the genres in the spinner it will display a toast, the toast isn't showing when clicking the spinner, the code isn't showing any errors ? any ideas why ? String spinnerSelection…
-2
votes
1 answer

Can TOAST display text from an online resource at random?

I am just wondering if a toast activity could print out a text taken from an online database (google spreadsheet or google doc) at random? using JSON maybe? Here is my code and right now it's just displaying random text but from the bank which I…
Jagmaster
  • 107
  • 4
  • 12
-2
votes
1 answer

Display a toast message on dialer screen while making an outgoing call in Android

I am developing an Android app and I am blocked at one place. I want to toast a one liner very small text in dialer screen while user dialed a number. This similar thing true-caller app has used. In similar way I want to display.
-2
votes
2 answers

Can't pass random integer when calling makeText()

I am new to android and was playing around with the makeText method of Toast class. I noticed that when calling makeText, I could not pass an integer for the duration parameter other than TOAST.LENGTH_LONG and TOAST.LENGTH_SHORT. Android studio…
Vivin
  • 1,327
  • 2
  • 9
  • 28
-2
votes
3 answers

Why Toast.maketoast is not working in the BroadcastReceiver class

I am getting the Error message while i am trying to call the Toast.makeText function inside the onReceive function of the BroadcastReceiver type class. This is not a duplicate of another Question because i am calling the show() method and this is…
-2
votes
1 answer

check box is not working to activate or deactivate sound in android

lam new starter in android,in my simple game app,I used check box to activate or deactivate sound, but when l run the app in emulator and tic on the check box to deactivate is not working and the music still on ,any help is appreciated import…
-2
votes
2 answers

Why does Toast need Context?

public static Toast makeText( Context context, int resId, int duration) As in above code, Context is needed to make a Toast. Explanation given by various resources is that Context is needed by the Toast class to be able to find and use the string’s…
Mandroid
  • 6,200
  • 12
  • 64
  • 134
-2
votes
2 answers

i have a mistake in my adapter class

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_messages, container, false); brands.add("microsoft"); …
-2
votes
2 answers

NullPointerException in Async onPostExecute

I'm calling MainActivity function sendToServer(arguments) in Retriver.java class, this function works fine when I'm working in mainactivity class. But when I call it from retriver.java i get nullPointExceltion Logcat: 12-29 02:24:07.772:…
John D
  • 23
  • 2
  • 8
-2
votes
2 answers

How to enable clicks while toast is visible

My application must show a couple of images at the bottom of each screen for a few seconds each time the user navigates between fragments. I have implemented it as a custom toast, and I activate it with each navigation. It looks good, but the user…
async8192
  • 199
  • 2
  • 8
-2
votes
1 answer

Android set edittext values into multiple textviews

I want to set text of edittext into multiple textviews like if i enter 'HELLO', then H will be set to a textview, E to another. I have written below code where text is showing one by one on Toast message. App crashes if i use textview.settext(); …
user3021522
  • 61
  • 1
  • 3
  • 10