public abstract class BaseRecyclerViewAdapter<T>
extends <any>
描述:万能适配器(采用泛型) 主要是针对RecyclerView的适配器
1.(更加厉害) 抽取出来的模板适配器,任何适配器继承该适配器,就很容易实现适配器功能。
2.支持多个item
3.RecyclerView不同与AbsListView(ListView、GrideView)具有点击setOnItemClickListener事件监听
故本代码中自己新增了setOnItemClickListener、setOnItemLongClickListener,来解决RecyclerView的OnItem事件
作者: zhouyou
日期: 2016/8/25 10:29
版本: v3.0
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
BaseRecyclerViewAdapter.OnItemClickListener<T> |
static interface |
BaseRecyclerViewAdapter.OnItemLongClickListener<T> |
| 限定符和类型 | 字段和说明 |
|---|---|
protected android.content.Context |
mContext |
protected int[] |
mLayoutIds |
protected android.view.LayoutInflater |
mLInflater |
protected java.util.List<T> |
mList |
| 构造器和说明 |
|---|
BaseRecyclerViewAdapter(android.content.Context context) |
BaseRecyclerViewAdapter(android.content.Context context,
int... layoutIds) |
BaseRecyclerViewAdapter(java.util.List<T> data,
android.content.Context context)
在初始化的时候不能确定layoutId,才可以不提供,但是必须重checkLayoutId方法
|
BaseRecyclerViewAdapter(java.util.List<T> data,
android.content.Context context,
int... layoutId) |
| 限定符和类型 | 方法和说明 |
|---|---|
int |
checkLayout(T item,
int position) |
protected BaseRecyclerViewHolder |
createViewHolder(android.view.View view,
int layoutId) |
int |
getItemCount() |
int |
getItemViewType(int position) |
protected android.view.View |
inflateItemView(int layoutId,
android.view.ViewGroup viewGroup)
解析布局资源
|
boolean |
isEmpty() |
protected abstract void |
onBindData(BH viewHolder,
int position,
T item)
绑定数据到Item View上
|
protected void |
onBindItemClickListener(BH holder,
int position)
注册item点击、长按事件
|
void |
onBindViewHolder(BH holder,
int position) |
void |
onBindViewHolder(BH holder,
int position,
java.util.List<java.lang.Object> payloads) |
BH |
onCreateViewHolder(android.view.ViewGroup parent,
int viewType) |
void |
setOnItemClickListener(BaseRecyclerViewAdapter.OnItemClickListener onItemClickListener) |
void |
setOnItemLongClickListener(BaseRecyclerViewAdapter.OnItemLongClickListener onItemLongClickListener) |
protected java.util.List<T> mList
protected android.content.Context mContext
protected android.view.LayoutInflater mLInflater
protected int[] mLayoutIds
public BaseRecyclerViewAdapter(java.util.List<T> data, android.content.Context context, int... layoutId)
data - 数据源context - 上下文layoutId - 布局Idpublic BaseRecyclerViewAdapter(android.content.Context context,
int... layoutIds)
public BaseRecyclerViewAdapter(android.content.Context context)
public BaseRecyclerViewAdapter(java.util.List<T> data, android.content.Context context)
在初始化的时候不能确定layoutId,才可以不提供,但是必须重checkLayoutId方法
data - 数据源context - 上下文public int getItemViewType(int position)
public BH onCreateViewHolder(android.view.ViewGroup parent, int viewType)
protected BaseRecyclerViewHolder createViewHolder(android.view.View view, int layoutId)
protected android.view.View inflateItemView(int layoutId,
android.view.ViewGroup viewGroup)
layoutId - viewGroup - public void onBindViewHolder(BH holder, int position, java.util.List<java.lang.Object> payloads)
public void onBindViewHolder(BH holder, int position)
public int getItemCount()
protected abstract void onBindData(BH viewHolder, int position, T item)
viewHolder - position - 数据的位置item - 数据项public int checkLayout(T item, int position)
public boolean isEmpty()
public void setOnItemClickListener(BaseRecyclerViewAdapter.OnItemClickListener onItemClickListener)
public void setOnItemLongClickListener(BaseRecyclerViewAdapter.OnItemLongClickListener onItemLongClickListener)
protected final void onBindItemClickListener(BH holder, int position)
holder - position -