58 lines
1.4 KiB
Java
58 lines
1.4 KiB
Java
package com.gh.base;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
import android.view.View;
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
/**
|
|
* 目前仅提供butterknife bind方法
|
|
*
|
|
* @author CsHeng
|
|
* @Date 16/06/2017
|
|
* @Time 9:55 AM
|
|
*/
|
|
|
|
public abstract class BaseRecyclerViewHolder<T> extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
|
private T mData;
|
|
private OnListClickListener mListClickListener;
|
|
|
|
public BaseRecyclerViewHolder(View itemView) {
|
|
super(itemView);
|
|
ButterKnife.bind(this, itemView);
|
|
}
|
|
|
|
/**
|
|
* 具体的设置监听在childViewHolder 设置
|
|
*
|
|
* @param itemView
|
|
* @param data 一般情况下只传列表数据
|
|
* @param listClickListener 列表事件接口
|
|
*/
|
|
public BaseRecyclerViewHolder(View itemView, T data, OnListClickListener listClickListener) {
|
|
this(itemView);
|
|
this.mData = data;
|
|
this.mListClickListener = listClickListener;
|
|
}
|
|
|
|
public BaseRecyclerViewHolder(View itemView, OnListClickListener listClickListener) {
|
|
this(itemView);
|
|
this.mListClickListener = listClickListener;
|
|
}
|
|
|
|
public void setClickData(T clickData) {
|
|
this.mData = clickData;
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View view) {
|
|
try {
|
|
mListClickListener.onListClick(view, getAdapterPosition(), mData);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
}
|