AmanSharma
AmanSharma

Reputation: 841

<AdapterClass> either be declared abstract or implement abstract method onBindViewHolder(VH,int) in <AdapterClass>

public class SubjectAdapter extends RecyclerView.Adapter<SubjectHolder> {
private ArrayList<Subjects> subjectsArrayList=new ArrayList<Subjects>();
private  Context mContext;


public SubjectAdapter(Context context) {
    mContext=context;
    populateList();
    this.subjectsArrayList = subjectsArrayList;
}

public void populateList(){
//Populates subjectArrayList 
}
@Override
public void onBindViewHolder(@NonNull SubjectHolder holder, int position, @NonNull List payloads) {
    super.onBindViewHolder(holder, position, payloads);
    Subjects subject=subjectsArrayList.get(position);
    holder.setSubjectName(subject.getSubjectCode());


}

@NonNull
@Override
public SubjectHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    LayoutInflater layoutInflater=LayoutInflater.from(parent.getContext());
    View cardView=layoutInflater.inflate(R.layout.activity_card,parent,false);
    SubjectHolder subjectHolder=new SubjectHolder(cardView);
    return subjectHolder;
}


@Override
public int getItemCount() {
    return subjectsArrayList.size();
}

}

I read answer to similar question , but it doesnt seem to work out. SubjectHolder is a class , which holds TextView and GridView. I was actually trying to get a view like this , enter image description here

Upvotes: 1

Views: 1011

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007321

There are two onBindViewHolder() methods. The two-parameter one must be implemented, because it is declared as abstract in RecyclerView.Adapter. You implemented the three-parameter onBindViewHolder() method, which is fine, but you still need the two-parameter one.

Upvotes: 1

Related Questions