该项目是学习如何封装 loadmore 功能时候的实验作品,未投入生产环境测试,如有需要,请移步至 PullRecycler
Thanks Cube-Sdk,秋哥的 loadmore 模块真的写得很好!
// 支持 Click 事件
mSampleAdapter.setOnItemClickListener(new OnRcvItemClickListener() {
@Override public void onItemClick(View v, int position) {
Toast.makeText(MainActivity.this, "点击事件支持,item position -->>" + position,
Toast.LENGTH_SHORT).show();
}
});
// 支持 LongClick 事件
mSampleAdapter.setOnItemLongClickListener(new OnRcvItemLongClickListener() {
@Override public boolean onItemLongClick(View view, int position) {
Toast.makeText(MainActivity.this, "长按点击事件支持,item position -->>" + position,
Toast.LENGTH_SHORT).show();
return true;
}
});
mRecyclerView.setAdapter(mSampleAdapter);
mRecyclerView.useDefaultFooter(); // 请在 setAdapter 之后设置默认的 footer
mRecyclerView.setLoadMoreHandler(new ILoadMoreHandler() {
@Override public void onLoadMore() {
simulateLoadMoreData();
}
});
-
内容是否为空
-
是否有更多数据
/**
*
* @param isEmpty fetch 的数据列表是否为空
* @param hasMore 是否还有更多数据
*/
@Override public void onLoadMoreCompleted(boolean isEmpty, boolean hasMore) {
}
/**
*
* @param errorCode 错误码
* @param errorMsg 错误信息
*/
@Override public void onLoadMoreFailed(int errorCode, String errorMsg) {
}
/**
*
* 对 LoadMoreView 的抽象
*/
public interface ILoadMoreUIHandler {
// 加载中
void onLoading();
// 加载完毕
void onLoadFinish(boolean isEmpty, boolean hasMore);
// 加载出错
void onLoadError(int errorCode, String errorMsg);
// 等待被点击加载更多
void onWaitToLoadMore();
}
具体可以参考 DefaultLoadMoreFooterView 这个栗子!
1.当 LayoutManager 为 LinearLayoutManager
时
2.当 LayoutManager 为 GridLayoutManager
时
3.当 LayoutManager 为 StaggeredGridLayoutManager
时
// 请自行想象...