-2

I am new to android and was playing around with the makeText method of Toast class. I noticed that when calling makeText, I could not pass an integer for the duration parameter other than TOAST.LENGTH_LONG and TOAST.LENGTH_SHORT. Android studio warned that it has been annotated with @intDef but when I opened the source code for Toast class, I couldn't find where the parameter was annotated. Any idea how this is enforced?

My target SDK version is API 19: Android 4.4 (KitKat). The signature is:

public static Toast makeText(Context context, CharSequence text, int duration)

Vivin
  • 1,327
  • 2
  • 9
  • 28

2 Answers2

0

In Android 5.1.1, the duration parameter of Toast.makeText() is annotated with @Duration. This annotation is in turn annotated with @IntDef.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • But why can't I see it? And if the API 19 doesn't annotate it, why should I get the error? Sorry I am a bit confused. Can you please add some more explanation to the answer? – Vivin Sep 26 '16 at 03:23
0

below code is working for me

     final int SHORT_DELAY = 2000; // 2 seconds

  Toast.makeText(getActivity(),String.valueOf(12314),SHORT_DELAY).show();
Rissmon Suresh
  • 13,173
  • 5
  • 29
  • 38