show Tip Dialog using Toast - Android User Interface

Android examples for User Interface:Toast

Description

show Tip Dialog using Toast

Demo Code


//package com.java2s;

import android.content.Context;

import android.view.Gravity;

import android.widget.Toast;

public class Main {
    private static Toast showToast = null;

    public static void showTip(Context context, String text, boolean isInter) {
        if (null == showToast) {
            showToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        } else {//w  ww  .j  a  v  a2 s  .co  m
            if (isInter) {
                showToast.cancel();
                showToast = Toast.makeText(context, text,
                        Toast.LENGTH_SHORT);
            } else {
                showToast.setText(text);
            }
        }
        showToast.setGravity(Gravity.BOTTOM, 0, 0);
        showToast.show();
    }

    public static void showTip(Context context, int resId, boolean isInter) {
        if (null == showToast) {
            showToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
        } else {
            if (isInter) {
                showToast.cancel();
                showToast = Toast.makeText(context, resId,
                        Toast.LENGTH_SHORT);
            } else {
                showToast.setText(resId);
            }
        }
        showToast.setGravity(Gravity.BOTTOM, 0, 0);
        showToast.show();
    }
}

Related Tutorials