public abstract class XAdapter<T>
extends RecyclerView.Adapter
Item可以使用不同的Mark加载不同的布局,也可以与RN的ScrollView一样,使用不同的Mark来达到所有Holder不重用,在列表数量大的时候请谨慎使用不重复的Mark
使用getViewTypeUnitForLayout(Object)来自定义Holder
使用bindingHolder(CustomHolder, List, int) 和creatingHolder(CustomHolder, ViewTypeUnit) 来展示
Header可以添加多个
bindingHeader(CustomHolder, int)和creatingHeader(CustomHolder, int)
Footer默认为2个,一个是加载信息,另一个是可自定义的Footer,重写下面方法实现
bindingFooter(CustomHolder)和creatingFooter(CustomHolder)
(在第一版中部分注释我不用英文,可惜水平有限且并不直观,后面添加了中文注释)
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
XAdapter.ILoadMoreListener
加载更多接口
|
| 限定符和类型 | 字段和说明 |
|---|---|
protected android.content.Context |
context
Context
|
static int |
LOADER_CAN_LOAD |
static int |
LOADER_INIT
加载状态
LOADER_NO_DATA 没有数据
LOADER_NO_MORE 已加载全部,有footerLayoutId显示Footer
LOADER_CAN_LOAD 可以加载更多
LOADER_LOADING 正在加载中,等待LoadMoreListener返回结果
LOADER_RETRY 加载更多失败
|
static int |
LOADER_LOADING |
static int |
LOADER_NO_DATA |
static int |
LOADER_NO_MORE |
static int |
LOADER_RETRY |
static int |
VIEW_TYPE_BLANK
空布局Mark
|
static int |
VIEW_TYPE_FOOTER
Footer布局Mark
|
static int |
VIEW_TYPE_FOOTER_LOADING
Footer 加载中布局Mark
|
static int |
VIEW_TYPE_FOOTER_NO_DATA
Footer 没有数据布局Mark
|
static int |
VIEW_TYPE_FOOTER_NO_MORE
Footer 没有更多布局Mark
|
static int |
VIEW_TYPE_FOOTER_RETRY
Footer 重试布局Mark
|
static int[] |
VIEW_TYPE_FOOTERS
Footers的几种新动态 布局Mark合集
|
| 构造器和说明 |
|---|
XAdapter(android.content.Context context)
use single Layout
|
XAdapter(android.content.Context context,
OnInitList initList) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addHeader(int headerLayoutId)
添加默认Header,Key值为0
|
void |
addHeader(int headerKey,
int headerLayoutId)
添加Header,避免使用Key为0的Header以免与默认Header发生碰撞
|
void |
addItem(T item)
添加Item
|
void |
addItemNoFilter(int pos,
T item)
this method can only use in no filter mode
|
protected void |
beforeSetDataList(java.util.List<T> dataList)
setDataList时,在Notify以前调用此方法,现在是空实现
|
protected void |
bindingFooter(CustomHolder holder)
Footer OnBind
|
protected void |
bindingFooterLoader(CustomHolder holder,
int layoutFooterViewType)
启用加载更多时绑定Footer
建议不想新建Layout的可以继承XAdapter
重写此方法,适应更种加载提示语等
|
protected void |
bindingHeader(CustomHolder holder,
int headerKey)
Header OnBind
|
void |
bindingHolder(CustomHolder holder,
java.util.List<T> dataList,
int pos)
绑定展示数据时执行,多次执行
|
void |
clearDataList()
useFilter() == true 时有效果
|
protected void |
creatingFooter(CustomHolder holder)
Footer的Holder创建
|
protected void |
creatingHeader(CustomHolder holder,
int headerKey)
Header的Holder 创建
|
void |
creatingHolder(CustomHolder holder,
ViewTypeUnit viewTypeUnit)
创建Holder时执行,只执行一次或被销毁后再次会被执行
|
T |
getCurrentItem(CustomHolder holder)
取得当前Holder的Item
|
int |
getHeaderCount() |
int |
getHeaderPos(int headerKey) |
T |
getItem(int itemPosWithoutHeaderCount)
取得列表Item
|
int |
getItemCount()
Please use getDataList().size() to get items count,this method would add header and Footer if they exist
|
int |
getItemViewType(int position)
when you use layout list, you can override this method when binding holder views
|
int |
getLayoutId(java.lang.String mark) |
int |
getLoadingLayoutId()
取得加载中LayoutId
|
XAdapter.ILoadMoreListener |
getLoadMoreListener()
加载更多接口
|
int |
getLoadRetryLayoutId()
取得重试的LayoutId
|
int |
getNoDataLayoutId()
取得没有数据的LayoutId
|
java.util.List<T> |
getNoFilteredDataList()
适配器中的所有数据,包括被过滤掉的数据
|
OnInitList |
getOnInitList()
取得实现的列表
|
java.util.List<T> |
getShowingList()
取得下在展示的数据集合
|
protected ViewTypeUnit |
getViewTypeUnitForLayout(T item)
根据Mark确定展示的Layout
override this method can show different holder for layout
don't return LAYOUT_FOOTER = -20331
|
protected void |
handleItemViewClick(CustomHolder holder,
T item,
int viewId,
ViewTypeUnit viewTypeUnit)
override this method to add holder rootView onclick event,when handle over continue to on ClickListener in creating holder set.
|
protected boolean |
handleItemViewLongClick(CustomHolder holder,
T item,
int viewId,
ViewTypeUnit viewTypeUnit) |
boolean |
hasFooter() |
boolean |
isHeader(int pos)
是否Header
|
void |
loadingMoreEnd(boolean noMoreData)
加载更多结束
|
void |
loadingMoreError()
加载更多异常
显示加载重试Footer
|
void |
onBindViewHolder(RecyclerView.ViewHolder holder,
int position)
展示
|
RecyclerView.ViewHolder |
onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
only do once method
or
not use immediately adapterPosition method, like clickListener
|
void |
onViewAttachedToWindow(RecyclerView.ViewHolder holder)
Called when a view created by this adapter has been attached to a window.
|
void |
openLoadAnimation()
To open the animation when loading
|
void |
openLoadAnimation(BaseAnimation animation)
Set Custom ObjectAnimator
|
void |
refreshedNoData()
没有数据
|
void |
removeItem(int pos) |
void |
setAnimationDuration(int animationDuration)
设置动画时长
|
void |
setAnimationInterpolator(android.view.animation.Interpolator animationInterpolator)
设置动画
|
void |
setDataList(java.util.List<T> dataList) |
protected java.util.List<T> |
setFilterForAdapter(java.util.List<T> mainList)
filter local main data list, it can use any time, it won't change the main data list.
|
void |
setFooter(int footerLayout)
设置Footer Layout
|
protected void |
setFullSpan(RecyclerView.ViewHolder holder)
thanks CymChad for this method
When set to true, the item will layout using all span area.
|
void |
setLoadingLayout(int loadingLayoutId)
设置加载中LayoutId
|
void |
setLoadMoreListener(XAdapter.ILoadMoreListener loadMoreListener)
设置加载更多监听
|
void |
setLoadRetryLayoutId(int loadRetryLayoutId)
设置重试的LayoutId
|
void |
setNoDataLayoutId(int noDataLayoutId)
设置没有数据的LayoutId
|
void |
setNoMoreLayoutId(int noMoreLayoutId)
设置没有更多的LayoutId
|
void |
setShowNoDataFooter(boolean showNoDataFooter)
有数据时是是否展示没Footer
|
void |
setUseDefaultLoaderLayout(boolean useDefaultLoaderLayout)
设置是否使用默认的Laoder Layout
|
protected void |
startItemAnimation(BaseAnimation animation,
RecyclerView.ViewHolder holder)
set anim to start when loading
|
void |
updateItem(int pos,
T item)
更新Item
|
protected boolean |
useFilter()
是否使用过滤列表
|
public static final int VIEW_TYPE_BLANK
public static final int VIEW_TYPE_FOOTER
public static final int VIEW_TYPE_FOOTER_LOADING
public static final int VIEW_TYPE_FOOTER_NO_MORE
public static final int VIEW_TYPE_FOOTER_RETRY
public static final int VIEW_TYPE_FOOTER_NO_DATA
public static final int[] VIEW_TYPE_FOOTERS
public static final int LOADER_INIT
public static final int LOADER_NO_DATA
public static final int LOADER_NO_MORE
public static final int LOADER_CAN_LOAD
public static final int LOADER_LOADING
public static final int LOADER_RETRY
protected android.content.Context context
public XAdapter(android.content.Context context)
context - public XAdapter(android.content.Context context,
OnInitList initList)
public RecyclerView.ViewHolder onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
parent - viewType - public void onBindViewHolder(RecyclerView.ViewHolder holder,
int position)
holder - position - public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
setFullSpan(RecyclerView.ViewHolder)holder - protected void setFullSpan(RecyclerView.ViewHolder holder)
holder - True if this item should traverse all spans.protected void startItemAnimation(BaseAnimation animation, RecyclerView.ViewHolder holder)
animation - holder - public void openLoadAnimation(BaseAnimation animation)
animation - ObjectAnimatorpublic void openLoadAnimation()
public void creatingHolder(CustomHolder holder, ViewTypeUnit viewTypeUnit) throws java.lang.Exception
holder - viewTypeUnit - java.lang.Exceptionpublic void bindingHolder(CustomHolder holder, java.util.List<T> dataList, int pos) throws java.lang.Exception
holder - dataList - pos - java.lang.Exceptionprotected ViewTypeUnit getViewTypeUnitForLayout(T item)
item - public int getItemViewType(int position)
position - public int getItemCount()
public boolean isHeader(int pos)
pos - public T getItem(int itemPosWithoutHeaderCount)
itemPosWithoutHeaderCount - 列表中的Item位置, 不包括Header的Item,
如使用getAdapterPosition()需要减掉getHeaderCount()public T getCurrentItem(CustomHolder holder)
holder - public OnInitList getOnInitList()
public void setAnimationDuration(int animationDuration)
animationDuration - public void setAnimationInterpolator(android.view.animation.Interpolator animationInterpolator)
animationInterpolator - public boolean hasFooter()
public int getHeaderCount()
public int getHeaderPos(int headerKey)
public int getLayoutId(java.lang.String mark)
public java.util.List<T> getNoFilteredDataList()
public java.util.List<T> getShowingList()
public void setDataList(java.util.List<T> dataList)
public void clearDataList()
public void removeItem(int pos)
public void addItemNoFilter(int pos,
T item)
pos - item - public void updateItem(int pos,
T item)
pos - item - public void addItem(T item)
item - public void setFooter(int footerLayout)
footerLayout - public void addHeader(int headerLayoutId)
headerLayoutId - public void addHeader(int headerKey,
int headerLayoutId)
headerKey - headerLayoutId - protected void creatingHeader(CustomHolder holder, int headerKey) throws java.lang.Exception
holder - headerKey - java.lang.Exceptionprotected void bindingHeader(CustomHolder holder, int headerKey) throws java.lang.Exception
holder - headerKey - java.lang.Exceptionprotected void creatingFooter(CustomHolder holder)
holder - protected void bindingFooter(CustomHolder holder)
holder - protected void bindingFooterLoader(CustomHolder holder, int layoutFooterViewType)
holder - layoutFooterViewType - LAYOUT_FOOTERprotected void beforeSetDataList(java.util.List<T> dataList)
dataList - protected void handleItemViewClick(CustomHolder holder, T item, int viewId, ViewTypeUnit viewTypeUnit)
holder - item - viewTypeUnit - protected boolean handleItemViewLongClick(CustomHolder holder, T item, int viewId, ViewTypeUnit viewTypeUnit)
protected java.util.List<T> setFilterForAdapter(java.util.List<T> mainList)
mainList - protected boolean useFilter()
public void loadingMoreEnd(boolean noMoreData)
noMoreData - true:没有更多的数据了, false:可以再次加载更多public void loadingMoreError()
public void refreshedNoData()
public XAdapter.ILoadMoreListener getLoadMoreListener()
public void setLoadMoreListener(XAdapter.ILoadMoreListener loadMoreListener)
loadMoreListener - public void setLoadingLayout(int loadingLayoutId)
loadingLayoutId - public int getLoadingLayoutId()
public void setNoMoreLayoutId(int noMoreLayoutId)
noMoreLayoutId - public int getNoDataLayoutId()
public void setNoDataLayoutId(int noDataLayoutId)
noDataLayoutId - public int getLoadRetryLayoutId()
public void setLoadRetryLayoutId(int loadRetryLayoutId)
loadRetryLayoutId - public void setUseDefaultLoaderLayout(boolean useDefaultLoaderLayout)
useDefaultLoaderLayout - public void setShowNoDataFooter(boolean showNoDataFooter)
showNoDataFooter -