如何将进度条放入recycleview?
当用户在列表中播放歌曲时,我必须显示进度条,请帮助我。当前当用户选择任何歌曲时,用户仍在等待播放歌曲。
谢谢。
这是我的代码:
public class CustomAdapterNew extends RecyclerView.Adapter<CustomAdapterNew.MyViewHolder> {
private ArrayList<SlockDataModel> dataSet;
Context context;
private static LayoutInflater inflater = null;
public static MediaPlayer mediaPlayer = new MediaPlayer();
Boolean check = false;
private static final String TAG = "CustomAdapter";
int current = -1;
public static class MyViewHolder extends RecyclerView.ViewHolder {
TextView title;
ImageView img_play;
AVLoadingIndicatorView progress;
public MyViewHolder(View itemView) {
super(itemView);
this.title = (TextView) itemView.findViewById(R.id.text_slock);
this.img_play = (ImageView) itemView.findViewById(R.id.img_play);
progress = (AVLoadingIndicatorView) itemView.findViewById(R.id.avi);
itemView.setTag(this);
}
}
public CustomAdapterNew(Context slock, ArrayList<SlockDataModel> data) {
this.dataSet = data;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.slock_list_items, parent, false);
final MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int listPosition) {
final View mainView = holder.itemView;
TextView title = holder.title;
final ImageView btn_play = holder.img_play;
title.setText(dataSet.get(listPosition).getValue());
title.setTag(listPosition);
if(listPosition != current){
btn_play.setImageResource(R.mipmap.play_btn);
} else {
btn_play.setImageResource(R.mipmap.stop_btn);
}
title.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SlockNew.progress.setVisibility(View.VISIBLE);
String str = dataSet.get(listPosition).getSong();
v.getTag(listPosition);
View oldSongView = SlockNew.lv.getLayoutManager().findViewByPosition(current);
if (!check || current != listPosition) {
if (current != -1) {
mediaPlayer.release();
btn_play.setImageResource(R.mipmap.stop_btn);
((ImageView) oldSongView.findViewById(R.id.img_play)).setImageResource(R.mipmap.play_btn);
}
playsong(str);
btn_play.setImageResource(R.mipmap.stop_btn);
check = true;
current = listPosition;
SlockNew.progress.setVisibility(View.INVISIBLE);
} else {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
mediaPlayer.reset();
mediaPlayer.stop();
mediaPlayer.release();
}
check = false;
Log.i(TAG, "ELSE");
btn_play.setImageResource(R.mipmap.play_btn);
current = -1;
SlockNew.progress.setVisibility(View.INVISIBLE);
}
}
//Tapan
private void playsong(String str) {
String url = str;
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
@Override
public int getItemCount() {
return dataSet.size();
}
}
最佳答案
尝试这个,
if(listPosition != current){
btn_play.setImageResource(R.mipmap.play_btn);
holder.progress.setVisibility(View.VISIBLE);
} else {
btn_play.setImageResource(R.mipmap.stop_btn);
holder.progress.setVisibility(View.GONE);
}
关于java - 将progressbar放入回收 View android,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42944263/