recycleview条目点击事件

xiaoxiao2021-02-28  11

package com.appc.jd.adapter; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.view.ViewGroup; import com.appc.jd.R; import com.appc.jd.holder.myholder; import com.appc.jd.moudle.bean.shouyebean; import com.bumptech.glide.Glide; import java.util.List; /**  * Created by Administrator on 2017/12/25.  */ public class adapter2 extends RecyclerView.Adapter<myholder> {     private List<shouyebean.MiaoshaBean.ListBeanX> list;     private Context context;     public adapter2(List<shouyebean.MiaoshaBean.ListBeanX> list, Context context) {         this.list = list;         this.context = context;     }     private adapter.OnItemClickListener mOnItemClickListener = null;     public static interface OnItemClickListener {         void onItemClick(View view, int position);     }     @Override     public myholder onCreateViewHolder(ViewGroup parent, int viewType) {         View view = View.inflate(context, R.layout.item3, null);         myholder myholder = new myholder(view);         view.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 if (mOnItemClickListener != null) {                     //注意这里使用getTag方法获取position                     Log.e("wangzi", "onClick: " + v.toString() + "++++++++++");                     int position = (int) v.getTag();                     Log.e("wangzi", "onClick: " + position + "++++++++++");                     mOnItemClickListener.onItemClick(v, position);                 }             }         });         return myholder;     }     @Override     public void onBindViewHolder(myholder holder, int position) {         holder.itemView.setTag(position);         String s = list.get(position).getImages().toString();         String[] split = s.split("\\|");         Glide.with(context).load(split[0]).into(holder.iv); //        holder.tv.setText(list.get(position).getTitle());     }     @Override     public int getItemCount() {         return list.size();     }     public void setOnItemClickListener(adapter.OnItemClickListener listener) {         this.mOnItemClickListener = listener;     } }
转载请注明原文地址: https://www.6miu.com/read-1650288.html

最新回复(0)