gpt4 book ai didi

java - 将进度条放入recyclerview android

转载 作者:行者123 更新时间:2023-12-02 13:36:55 25 4
gpt4 key购买 nike

如何将进度条放入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 - 将进度条放入recyclerview android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42944263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com