Tuesday, 5 April 2011

Making Simple Toast Notification

We use toast notification quite often, especially during testing. Toast notification is a pop up window to show certain message to the users. Toast notification does not involve user interaction (there is no OK, Cancel, Yes, No etc). It will automatically fade in and out. See the sample code below:-

In .java file, put the following code:-

import android.widget.Toast;

public class activityTestToast extends Activity 
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) 

        //this line will pop up the message when the application is created
        Toast.makeText(this, "Cikucak!!", Toast.LENGTH_SHORT).show();


1. Replace the work "Cikucak" with any message you prefer.
2. Try LENGTH_SHORT or LENGTH_LONG and see the difference

It's quite simple, right?

1 comment:

sergoto said...

You can also find a simple tutorial here - http://android-apps-blog.blogspot.com/2011/04/how-to-display-simple-toast-notificatin.html