I have a problem displaying toast on an RecylerViewAdapter
with firebase. I was gonna use it on an image button which is delete as you can see below the onBindViewHolder
. But the problem is, getContext
doesn't work
public class AddClassAdapter extends FirebaseRecyclerAdapter<AddClass, AddClassAdapter.myViewHolder>{
/**
* Initialize a {@link RecyclerView.Adapter} that listens to a Firebase query. See
* {@link FirebaseRecyclerOptions} for configuration options.
*
* @param options
*/
private OnItemClickListener listener, listener1;
public AddClassAdapter(@NonNull FirebaseRecyclerOptions<AddClass> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull myViewHolder holder, int position, @NonNull AddClass model) {
holder.className.setText(model.getClassName);
holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(, "Course Added Successfully", Toast.LENGTH_SHORT).show();
}
});
}
I've tried getContext()
but it gives me an error, also, I tried using these in the main activity:
Context context = getApplicationContext();
AddClassAdapter adapter = new AddClassAdapater(context);
But it won't work and gives an error of
Required type:FirebaseRecyclerOptions <com.example.attendancechecker_application.AddClass>
Is there a way to have a toast in the RecyclerViewAdapter?