show Toast for Long or Short - Android android.widget

Android examples for android.widget:Toast

Description

show Toast for Long or Short

Demo Code

import android.app.Activity;
import android.widget.Toast;

public class Main {

  public static void show(final Activity activity, final String message, final boolean isLong) {
    final String msg = message;
    activity.runOnUiThread(new Runnable() {
      public void run() {
        int duration = Toast.LENGTH_SHORT;
        if (isLong) {
          duration = Toast.LENGTH_LONG;/*from w w w .j a v  a2s .  co m*/
        }

        Toast.makeText(activity, msg, duration).show();
      }
    });
  }
  public static void show(Activity activity, int msgResID) {
    Toast.makeText(activity, msgResID, Toast.LENGTH_SHORT).show();
  }

}

Related Tutorials