public class CustomToast {
private static Toast mToast;
private static Handler mHandler = new Handler();
private static Runnable r = new Runnable() {
public void run() {
mToast.cancel();
}
};
public static void showToast(Context mContext, String message, int duration) {
mHandler.removeCallbacks(r);
if (mToast != null)
mToast.setText(message);
else
mToast = Toast.makeText(mContext, message, Toast.LENGTH_SHORT);
mHandler.postDelayed(r, duration);
mToast.show();
}
public static void showToast(Context mContext, int resId, int duration) {
showToast(mContext, mContext.getResources().getString(resId), duration);
}
}