Java tutorial
//package com.java2s; import android.content.Context; import android.widget.Toast; public class Main { private static Toast toast; public static Toast showShort(Context context, CharSequence message) { if (null == toast) { toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); return toast; } public static Toast showShort(Context context, int message) { if (null == toast) { toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); return toast; } public static Toast show(Context context, CharSequence message, int duration) { if (null == toast) { toast = Toast.makeText(context, message, duration); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); return toast; } public static void show(Context context, int message, int duration) { if (null == toast) { toast = Toast.makeText(context, message, duration); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); } }