Как мне воспроизвести песню при нажатии на Лист RecycerView?
именно надо написать для onClick
public class SongAdapter extends RecyclerView.Adapter<SongAdapter.VH> {
//Закрытый класс
public static ArrayList<Song> songList;
private Context context;
SongFragment songFragment;
protected OnClickListen myOnClickListen;
public SongAdapter(AppCompatActivity activity, ArrayList<Song> songList, boolean b, boolean b1) {
this.songList = songList;
this.context = context;
this.songFragment = songFragment;
}
@NonNull
@Override
public VH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
// список через класс LayoutInflater
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.song_list, viewGroup, false);
VH vh = new VH(v, myOnClickListen);
return vh;
}
@Override
public void onBindViewHolder(@NonNull VH holder, int position) {
Song song = songList.get(position);
if ( song != null ) {
holder.titl.setText(song.title);
holder.arts.setText(song.artistName);
ImageLoader.getInstance().displayImage(getImage(song.albumId).toString(), holder.imagView,
new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnLoading(R.drawable.note3)
.resetViewBeforeLoading(true).build());
}
}
public static Uri getImage(long albumId) {
return ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"), albumId);
}
@Override
public int getItemCount() {
return songList.size();
}
public class VH extends RecyclerView.ViewHolder implements View.OnClickListener {
public SquareImageView imagView;
public TextView titl, arts;
public VH(@NonNull View itemView, OnClickListen onClickListen) {
super(itemView);
imagView = itemView.findViewById(R.id.songthumb);
titl = itemView.findViewById(R.id.sogname);
arts = itemView.findViewById(R.id.artistname);
this.onClickListen = onClickListen;
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
}
}
}