【发布时间】:2018-01-15 13:22:48
【问题描述】:
我正在使用this 库来实现可扩展的RecyclerView。我已经实现了它,它工作正常。但我想要的是只有当我点击一个特定的视图时,该组才应该展开。现在发生的事情是,如果我单击 RecyclerView 项目上的任意位置,该组就会展开。我有一个ImageView,当我单击该 ImageView 时,该组才会展开。我该如何实现?
RecyclerViewAdapter.java:
public class GenresSongAdapter extends ExpandableRecyclerViewAdapter<SongDetailsViewHolder, OptionViewHolder> {
private Context mContext;
public GenresSongAdapter(Context context, List<? extends ExpandableGroup> groups) {
super(groups);
mContext = context;
}
@Override
public SongDetailsViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row_song, parent, false);
return new SongDetailsViewHolder(view);
}
@Override
public OptionViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row_artists, parent, false);
return new OptionViewHolder(view);
}
@Override
public void onBindChildViewHolder(OptionViewHolder holder, int flatPosition, ExpandableGroup group, int childIndex) {
ArtistsModel artistsModel = (ArtistsModel) group.getItems().get(childIndex);
holder.ArtistText.setText(artistsModel.getArtistsName());
}
@Override
public void onBindGroupViewHolder(SongDetailsViewHolder holder, int flatPosition, ExpandableGroup songInfo) {
holder.setSongDetails(mContext, songInfo);
}
}
SongDetailsViewHolder.java
class SongDetailsViewHolder extends GroupViewHolder {
public TextView songName;
public TextView artistName;
public TextView duration;
public ImageView iv_artwork;
public SongDetailsViewHolder(View itemView) {
super(itemView);
songName = (TextView) itemView.findViewById(R.id.SongName);
artistName = (TextView) itemView.findViewById(R.id.ArtistName);
duration = (TextView) itemView.findViewById(R.id.duration);
iv_artwork = (ImageView) itemView.findViewById(R.id.iv_artwork);
}
public void setSongDetails(Context mContext, ExpandableGroup songInfo) {
if (songInfo instanceof SongInfo) {
songName.setText(songInfo.getTitle());
artistName.setText(((SongInfo) songInfo).getArtistName());
duration.setText(((SongInfo) songInfo).getSongDuration());
Picasso.with(mContext).load(((SongInfo) songInfo).getImageURI()).placeholder(R.drawable.ic_launcher).into(iv_artwork);
}
}
}
OptionViewHolder.java
class OptionViewHolder extends ChildViewHolder {
TextView ArtistText;
public OptionViewHolder(View itemView) {
super(itemView);
ArtistText = itemView.findViewById(R.id.ArtistText);
}
}
【问题讨论】:
-
随意修改 ExpandableRecyclerViewAdapter(不管它是什么)源以满足您的需求......最终请图书馆的作者这样做
标签: android android-recyclerview expandablerecyclerview