Android Utililty Methods Toast Create

List of utility methods to do Toast Create

Description

The list of methods to do Toast Create are organized into topic(s).

Method

StringformatToastDist(String message, int value, String unit)
format Toast Dist
if (unit.equals("km"))
    message += ": " + value + " km";
else
    message += ": " + KmToMiles(value) + " miles";
return message;
StringformatToastTemp(String message, int value, String unit)
format Toast Temp
if (unit.equals("c"))
    message += ": " + value + "?C";
else
    message += ":" + CelciusToFahrenheit(value) + "?F";
return message;
voidshowMessage(final Activity activity, final String message)
show Message
activity.runOnUiThread(new Runnable() {
    public void run() {
        Toast.makeText(activity, message, Toast.LENGTH_LONG).show();
});
voidshowToast(Activity activity, String message)
show Toast
Toast.makeText(activity.getApplicationContext(), message,
        Toast.LENGTH_SHORT).show();
voidshowToast(final Activity ctx, final String text, final int position, final boolean alive)
show Toast
ctx.runOnUiThread(new Runnable() {
    @Override
    public void run() {
        if (!alive) {
            return;
        Toast toast = Toast.makeText(ctx, text, Toast.LENGTH_SHORT);
        toast.setGravity(position, 0, 0);
...
voidmakeToast(String msg, int length, Activity mainAct)
make Toast
Toast.makeText(mainAct, msg, length).show();
voiddisplayToast(String message, Activity activity)
display Toast
Toast toast = Toast.makeText(activity, message, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL
        | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
voidshowToast(Context context, String message)
show Toast
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
voidshowToast(Context context, int id)
show Toast
if (null != context) {
    Toast.makeText(context, id, Toast.LENGTH_SHORT).show();
voidshowToast(Context context, int stringId)
show Toast
Toast toast = Toast.makeText(context, context.getString(stringId),
        Toast.LENGTH_LONG);
toast.show();