在 ListView 中,一般使用 BaseAdapter。BaseAdapter 中有个方法 public int getItemViewType(int position) ,一般重写它,根据 position 的不同,自定义不同的 type。然后在 getView() 中,根据 viewType 的不同,创建不同的 view。 RecyclerView 其实也是类似的。 RecyclerView.Adapter 中,有方法 public int getItemViewType(int position),来设定 viewType;在 createViewHolder() 中,使用,源码: public final VH createViewHolder(ViewGroup parent, int viewType) { TraceCompat.beginSection(TRACE_CREATE_VIEW_TAG); final VH holder = onCreateViewHolder(parent, viewType); holder.mItemViewType = viewType; TraceCompat.endSection(); return holder; } 该方法是 final 的,即不能重写。所以要重写的是 public abstract VH onCreateViewHolder(ViewGroup parent, int viewType)。 接着在 bindViewHolder() 中,根据 viewType 的不同,来绑定数据。该方法也是 final 的,能重写的方法是:public abstract void onBindViewHolder(VH holder, int position)