public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>{ private Context context; private List<Allbean.SongListBean> list; private OnItemClickListener listener; private OnItemLongClickListener llistener; public void setOnItemClickListener(OnItemClickListener listener){ this.listener=listener; } public void OnItemLongClickListener(OnItemLongClickListener llistener){ this.llistener=llistener; } public RecyclerViewAdapter(Context context, List<Allbean.SongListBean> list) { this.context = context; this.list = list; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context, R.layout.showview, null); ViewHolder holder = new ViewHolder(view); return holder; } @Override public void onBindViewHolder(ViewHolder holder, int position) { Glide.with(context).load(list.get(position).getAlbum_500_500()).into(holder.img); holder.tv1.setText(list.get(position).getAlbum_title()); holder.tv2.setText(list.get(position).getAuthor()); } @Override public int getItemCount() { return list.size(); } class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { private ImageView img; private TextView tv1; private TextView tv2; public ViewHolder(View itemView) { super(itemView); img = itemView.findViewById(R.id.img); tv1 =itemView.findViewById(R.id.tv1); tv2 =itemView.findViewById(R.id.tv2); itemView.setOnClickListener(this); itemView.setOnLongClickListener(this); } @Override public void onClick(View view) { if(listener!=null){ listener.onClick(view,getPosition()); } } @Override public boolean onLongClick(View view) { if(llistener!=null){ llistener.setLongClick(view,getPosition()); } return true; } } }
recyclerview适配器
最新推荐文章于 2024-04-01 16:12:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)