英文:
<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();
}
}
请注意,我已经只返回了你提供的代码部分的翻译,去除了问题陈述和描述部分。如果你有任何关于代码或其他技术问题的疑问,欢迎随时提问。
英文:
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 ,
答案1
得分: 1
有两个 onBindViewHolder()
方法。其中两个参数的那个必须被实现,因为在 RecyclerView.Adapter
中被声明为 abstract
。你实现了带有三个参数的 onBindViewHolder()
方法,这是没问题的,但你还需要那个带有两个参数的方法。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论