I am getting error while creating a Toast
Toast toast = Toast.makeText(this, text, duration);
I am getting cannot resolve ma
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.
in the onClick method try this
Toast.makeText(view.getContext(), "sorry", Toast.LENGTH_LONG).show();
it did work form me.
Try Toast toast = Toast.makeText(getActivity(), text, duration);
You may also wish to append .show()
if you want it to display
First add
import android.widget.Toast;
statement if you did not already and then
Toast.makeText(YourActvityName.this, "Your Text", Toast.LENGTH_SHORT).show();
Just like Blackbelt said the syntax of Toast is as follows:
Toast.makeText(Activity.this, "Message",Toast.<specify Lenght>).show();
where Activity.this
is the current activity, Message
is the string you want to show and Toast.length
is the length you want it to show it for.
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;
}