Cannot resolve maketext() method of Toast
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.
The makeText's signature is the following
public static Toast makeText (Context context, CharSequence text, int duration)
the first paramter has to be a context object. You put this
, but this
refers to this object and it can be something different from an Activity
(a Fragment
for instance).
In the onClick(View view)
click listener within a RecyclerView.ViewHolder
the context is retrieved with view.getContext()
, as in:
```
public class MyHolder extends RecyclerView.ViewHolder implements
View.OnClickListener {
public MyHolder(View itemView) {
super(itemView);
//...
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "the message",
Toast.LENGTH_SHORT).show();
}
```
this in your case might not be the object of the activity. You might be using the Toast.makeText method inside you Click Listener object. To resolve this you need to use getApplicationContext() :
Toast.makeText(getApplicationContext() , "Your Message", Toast.LENGTH_LONG);