Example usage for android.widget Toast makeText

List of usage examples for android.widget Toast makeText

Introduction

In this page you can find the example usage for android.widget Toast makeText.

Prototype

public static Toast makeText(Context context, @StringRes int resId, @Duration int duration)
        throws Resources.NotFoundException 

Source Link

Document

Make a standard toast that just contains a text view with the text from a resource.

Usage

From source file:Main.java

/**
 * Shows a toast with the methane level//from w ww .j  a v a  2 s.c  o m
 *
 * @param methane the methane level
 *
 * @param context the context
 */
public static void showMethaneToast(Integer methane, Context context) {
    String message = "Methane level: " + Integer.toString(methane);
    Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

public static void showMsg(final Activity act, final String msg, final boolean isLongShow) {
    act.runOnUiThread(new Runnable() {
        @Override/*  w ww.  j  a  v a 2  s. c o  m*/
        public void run() {
            // TODO Auto-generated method stub
            if (isLongShow) {
                Toast.makeText(act, msg, Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(act, msg, Toast.LENGTH_SHORT).show();
            }
        }
    });
}

From source file:Main.java

private static void showToast(final Context context, final String string) {
    Handler handler = new Handler(Looper.getMainLooper());

    handler.post(new Runnable() {

        @Override/*from  ww  w .j a va2 s  . com*/
        public void run() {
            Toast.makeText(context, string, Toast.LENGTH_LONG).show();

        }
    });
}

From source file:Main.java

public static void ToastMessage(Context cont, int msg) {
    if (cont == null || msg <= 0) {
        return;/*from w  ww. ja va 2  s . co  m*/
    }
    Toast.makeText(cont, msg, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

public static void toastMessage(Context context, String text) {
    if (TextUtils.isEmpty(text)) {
        return;//from   ww w .  jav a2 s .c om
    }
    Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

public static void safeToastMessageShow(Activity pActivity, String pToastMsg, int pToastLength) {
    final String toastMsg = pToastMsg;
    final int toastLength = pToastLength;
    final Activity activity = pActivity;

    activity.runOnUiThread(new Runnable() {
        @Override//from  www. j a  va 2  s.  com
        public void run() {
            Toast.makeText(activity.getApplicationContext(), toastMsg, toastLength).show();
        }
    });
}

From source file:Main.java

public static void showToast(Activity activity, int stringId) {
    String message = activity.getString(stringId);
    if (message != null) {
        Toast.makeText(activity, message, Toast.LENGTH_SHORT).show();
    }//from ww w .  jav  a 2 s  .  c o m
}

From source file:Main.java

public static void showToast(final Context c, final CharSequence text) {
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        public void run() {
            if (c == null)
                return;
            Toast.makeText(c, text, Toast.LENGTH_SHORT).show();
        }/*w  w  w. j  a  va 2s  . c  om*/
    });
}

From source file:Main.java

public static void makeToast(final Context context, final String text) {
    runInUIThread(new Runnable() {
        @Override/*  w w w. jav  a 2  s  . c o  m*/
        public void run() {
            Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:Main.java

public static void showSafeToast(final Context context, final String text) {
    sHandler.post(new Runnable() {
        @Override// w ww  .j  a  va  2  s  .  c o  m
        public void run() {
            Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
        }
    });
}