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

huangapple go评论80阅读模式
英文:

<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&lt;SubjectHolder&gt; {
private ArrayList&lt;Subjects&gt; subjectsArrayList=new ArrayList&lt;Subjects&gt;();
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 ,
<AdapterClass> either be declared abstract or implement abstract method onBindViewHolder(VH,int) in <AdapterClass>

答案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.

huangapple
  • 本文由 发表于 2020年4月11日 04:59:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/61148600.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定