RecyclerView onCreateViewHolder Return Type Incompatibility With Multiple Custom ViewHolders

前端 未结 2 1328
一向
一向 2020-12-18 19:57

I\'m trying to use multiple ViewHolders in a RecyclerView in order to swap these views out at run time. I have created two classes which extend RecyclerView.ViewHolder:

2条回答
  •  隐瞒了意图╮
    2020-12-18 20:31

    The RecyclerView.Adapter is a parameterized class that takes in a single ViewHolder type. Your definition probably looks like:

    public class RecyclerViewAdapter extends RecyclerView.Adapter
    

    It should be:

    public class RecyclerViewAdapter extends RecyclerView.Adapter
    

    Don't forget to have the right definition for onBindViewHolder as well. You need to override getItemViewType as well.

提交回复
热议问题