I am getting error while creating a Toast
Toast toast = Toast.makeText(this, text, duration);
I am getting cannot resolve ma
Was having similar issue too but
getContext()
did the trick for me
// If message field is empty show a toast and alert the user
if (TextUtils.isEmpty(message)) {
Toast.makeText(getContext(),"Please Enter a message", Toast.LENGTH_SHORT).show();
return;
}
I have faced similar problem in android studio, I resolve this issue by using getActivity()
instead of this
in the fragment
Toast.makeText(getActivity(), "Your Text", Toast.LENGTH_SHORT).show();
Have you imported the toast widget?
import android.widget.Toast;
You can also call show() in the same line if you want to output it straight away:
Toast toast = Toast.makeText(context, text, duration).show();
Hope that helps.
If you are trying to Toast
your text in the MainActivity then do this:
Toast.makeText(getApplicationContext(), "Your text", Toast.LENGTH_LONG).show();
I have faced a similar problem but in my case i found out that Xamarin c# and Java in Android studio have differences when calling some functions(same functions).
When using Xamarin and c#, then makeText becomes MakeText and show becomes Show as shown below:
Toast toast = Toast.MakeText(this, "Text", ToastLength.Long);
toast.Show();
Hope this helps:)
Try Toast toast = Toast.makeText(getActivity(), text, duration);
You may also wish to append .show()
if you want it to display