Skip to content

Instantly share code, notes, and snippets.

@sbelloz
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbelloz/e2191d54afb235856f0a to your computer and use it in GitHub Desktop.
Save sbelloz/e2191d54afb235856f0a to your computer and use it in GitHub Desktop.
Util class that shows a toast message
import android.app.Activity;
import android.widget.Toast;
/**
* Created with IntelliJ IDEA.
* User: SimoneBellotti
* Date: 23/12/2014
* Time: 17.26
*/
public class ToastUtils {
public static void showWorkInProgress(final Activity context) {
show(context, "Work In Progress");
}
public static void show(final Activity context, final int resId) {
if (context != null) {
show(context, context.getString(resId), Toast.LENGTH_SHORT);
}
}
public static void show(final Activity context, int resId, Object... args) {
if (context != null) {
final String msg = String.format(context.getString(resId), args);
show(context, msg, Toast.LENGTH_SHORT);
}
}
public static void show(final Activity context, final String message) {
show(context, message, Toast.LENGTH_SHORT);
}
public static void show(final Activity context, final String message, final int duration) {
if (context != null) {
context.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(context, message, duration).show();
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment