答案 0 :(得分:1)
您可以使用 ExpandableRecyclerView
。
通过在类的定义中包含GroupViewHolder和ChildViewHolder,您将看到onCreateGroupViewHolder和onCreateChildViewHolder方法返回正确的类型:+1:
public class GenreAdapter extends ExpandableRecyclerViewAdapter<GenreViewHolder, ArtistViewHolder> {
public GenreAdapter(List<? extends ExpandableGroup> groups) {
super(groups);
}
@Override
public GenreViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.list_item_genre, parent, false);
return new GenreViewHolder(view);
}
@Override
public ArtistViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.list_item_artist, parent, false);
return new ArtistViewHolder(view);
}
@Override
public void onBindChildViewHolder(ArtistViewHolder holder, int flatPosition, ExpandableGroup group,
int childIndex) {
final Artist artist = ((Artist) group).getItems().get(childIndex);
holder.setArtistName(artist.getName());
}
@Override
public void onBindGroupViewHolder(GenreViewHolder holder, int flatPosition,
ExpandableGroup group) {
holder.setGenreTitle(group);
}
}
请查看以下GitHub存储库,以获取有关如何实施的完整指南,
您的结果如下图所示,