在我的卡片视图中,有没有一种方法可以通过单击recyclerview项目来启动新的recyclerview列表。我也想在单击我的垂直recyclerview项目后使用水平recyclerview。并且此新的onclick水平recyclerview应该从被单击的项目开始。 下面是我的适配器类。 公共类RingtoneAdapter扩展了RecyclerView.Adapter {
private Context context;
private List<RingtoneObject> allSongs;
private boolean isAudioPlaying = false;
private boolean playPauseBtn = true;
private boolean progressbar = false;
MediaPlayer mediaPlayer1;
private Button playingView;
public RingtoneAdapter(Context context, List<RingtoneObject> allSongs) {
this.context = context;
if (allSongs != null)
this.allSongs = allSongs;
else allSongs = new ArrayList<RingtoneObject>();
this.allSongs = allSongs;
mediaPlayer1 = new MediaPlayer();
}
@NonNull
@Override
public RingtoneAdapter.RingtoneViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(context).inflate(R.layout.ringtone_items, viewGroup, false);
return new RingtoneAdapter.RingtoneViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull final RingtoneAdapter.RingtoneViewHolder ringtoneViewHolder, final int i) {
final RingtoneObject uploadCur = allSongs.get(i);
ringtoneViewHolder.audio_description.setText(uploadCur.getImgName());
ringtoneViewHolder.card_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), i + "", Toast.LENGTH_SHORT).show();
}
});
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
ringtoneViewHolder.cardb.setBackgroundColor(color);
ringtoneViewHolder.play_audio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (playPauseBtn) {
playingView = ringtoneViewHolder.play_audio;
if (mediaPlayer1.isPlaying()) {
ringtoneViewHolder.play_audio.setBackgroundResource(R.drawable.pay_image);
} else {
mediaPlayer1.start();
ringtoneViewHolder.play_audio.setBackgroundResource(R.drawable.stop_button);
}
playPauseBtn = false;
} else {
if (mediaPlayer1.isPlaying()) {
mediaPlayer1.stop();
ringtoneViewHolder.play_audio.setBackgroundResource(R.drawable.pay_image);
} else {
mediaPlayer1.start();
ringtoneViewHolder.play_audio.setBackgroundResource(R.drawable.stop_button);
}
playingView.setBackgroundResource(R.drawable.pay_image);
playPauseBtn = true;
}
playRingtone(uploadCur.getImgUrl(), ringtoneViewHolder);
}
});
ringtoneViewHolder.favourite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ringtoneViewHolder.favourite.getColorFilter() != null) {
ringtoneViewHolder.favourite.clearColorFilter();
ringtoneViewHolder.favourite.setBackgroundResource(R.drawable.ic_favorite_border_black_24dp);
} else {
ringtoneViewHolder.favourite.setColorFilter(ContextCompat.getColor(context,
R.color.new1color));
ringtoneViewHolder.favourite.setBackgroundResource(R.drawable.ic_favorite_black_24dp);
}
}
});
}
public void playRingtone(String imgUrl, RingtoneViewHolder ringtoneViewHolder) {
if (!isAudioPlaying) {
isAudioPlaying = true;
try {
mediaPlayer1.stop();
mediaPlayer1.setDataSource(imgUrl);
mediaPlayer1.prepare();
mediaPlayer1.start();
} catch (Exception e) {
e.getMessage();
}
} else {
mediaPlayer1.pause();
mediaPlayer1.reset();
isAudioPlaying = false;
}
}
@Override
public int getItemCount() {
return allSongs.size();
}
public class RingtoneViewHolder extends RecyclerView.ViewHolder {
public TextView audio_description;
public CardView card_view;
public Button play_audio;
public ImageView favourite;
public RelativeLayout cardb;
public ProgressBar progress;
public SeekBar seekBar;
public RingtoneViewHolder(@NonNull View itemView) {
super(itemView);
audio_description = itemView.findViewById(R.id.audio_description);
card_view = itemView.findViewById(R.id.card_View);
play_audio = itemView.findViewById(R.id.playPause_button);
favourite = itemView.findViewById(R.id.isFav);
cardb = itemView.findViewById(R.id.cardback);
seekBar = itemView.findViewById(R.id.seekbar);
progress = itemView.findViewById(R.id.progress_play);
}
}
}