CRTC Electronics

Click here to edit subtitle

Toast

A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive. For example, navigating away from an email before you send it triggers a "Draft saved" toast to let you know that you can continue editing later. Toasts automatically disappear after a timeout.


Here is a method called toast. This method takes a string parameter as the message like "hi, this is a message". Now when you call toast it displays immediately.


example:

toast("Hi, this is a message");





you can set the duration of the toast to  

  • LENGTH_SHORT
  • LENGTH_LONG


private void toast(final String message) 

{

   final Context context = this;

   runOnUiThread

   (

      new Runnable() 

      {

         @Override

         public void run() 

         {

            Toast.makeText(context, message, Toast.LENGTH_LONG).show();

         }

      }

   );

}