I am developing an Android app with Recyclerview + Cardview with GridLayout in this I got the error as in the title.
Reminders.java (Fragment Class)
Fragment does not extend Context
. You could pass the fragment's activity as context using getActivity()
;
However you can just call parent.getContext()
in onCreateViewHolder(ViewGroup parent, int viewType_
and remove context from the adapter.
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.cardview,parent,false);
return new MyViewHolder(view);
}
You can just send getContext()
as a parameter which is accessible from your Fragment.