Android Toast Create showToast(Context context, int id)

Here you can find the source of showToast(Context context, int id)

Description

show Toast

Declaration

public static void showToast(Context context, int id) 

Method Source Code

//package com.java2s;
import android.content.Context;

import android.os.*;
import android.widget.Toast;

public class Main {
    private static Handler handler;

    public static void showToast(final Context context, String text) {
        if (null == context) {
            return;
        }// w ww  .  j  ava  2s .c o  m
        if (Looper.myLooper() != Looper.getMainLooper()) {
            if (handler == null) {
                handler = new Handler(Looper.getMainLooper()) {
                    @Override
                    public void handleMessage(Message msg) {
                        String str = (String) msg.obj;
                        Toast.makeText(context, str, Toast.LENGTH_SHORT)
                                .show();
                        super.handleMessage(msg);
                    }
                };
            }
            Message message = handler.obtainMessage();
            message.obj = text;
            message.sendToTarget();
        } else {
            Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
        }
    }

    public static void showToast(Context context, int id) {
        if (null != context) {
            Toast.makeText(context, id, Toast.LENGTH_SHORT).show();
        }
    }
}

Related

  1. showToast(Activity activity, String message)
  2. showToast(final Activity ctx, final String text, final int position, final boolean alive)
  3. makeToast(String msg, int length, Activity mainAct)
  4. displayToast(String message, Activity activity)
  5. showToast(Context context, String message)
  6. showToast(Context context, int stringId)
  7. showToast(String text, Context context)
  8. showToast(final Context context, String text)
  9. showToast(final Context context, final String message)