Skip to content

Instantly share code, notes, and snippets.

@devrath
Created March 21, 2016 11:04
Show Gist options
  • Select an option

  • Save devrath/6273a542d0a350b6ae8a to your computer and use it in GitHub Desktop.

Select an option

Save devrath/6273a542d0a350b6ae8a to your computer and use it in GitHub Desktop.
Util Class For The Toast Functionality In Android
import android.content.Context;
import android.widget.Toast;
/**
* Some utility methods related with the Toast class.
*
* @author Devrath
*/
public class ToastUtils {
private ToastUtils() {
//Empty
}
public static void showError(final String message, final Context context) {
getToast(message, context).show();
}
public static void showShortMessage(String message, Context context) {
getToast(message, context, Toast.LENGTH_SHORT).show();
}
private static Toast getToast(String message, Context context) {
return getToast(message, context, Toast.LENGTH_LONG);
}
private static Toast getToast(String message, Context context, int length) {
return Toast.makeText(context, message, length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment