Android UI How to - Show different type of Toast








Question

We would like to know how to show different type of Toast.

Answer

/*from  ww  w. j  a  va  2 s.com*/
import android.content.Context;
import android.widget.Toast;

class ActivityUtils {

    public static void showInfoMessage(Context context, int message) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }
    
    public static void showErrorMessage(Context context, Throwable ex) {
        Toast.makeText(context, ex.getLocalizedMessage(), Toast.LENGTH_LONG).show();
    }
    
    public static void showErrorMessage(Context context, int message, Object... args) {
        Toast.makeText(context, context.getString(message, args), Toast.LENGTH_LONG).show();
    }
    
}