3秒钟不懂你砍我:RecyclerView下拉刷新和上拉加载更多
来源:互联网 发布:台湾人逛淘宝的感想 编辑:程序博客网 时间:2024/06/06 19:32
借鉴自:http://blog.csdn.net/jerrywu145/article/details/52225898
先直接写可以拿去用的东西。
1.下拉刷新 SwipeRefreshLayout
2.上拉加载更多 RecyclerView.OnScrolListener
下拉刷新
布局
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /></android.support.v4.widget.SwipeRefreshLayout>使用
@BindView(R.id.recyclerView)RecyclerView mRecyclerView;@BindView(R.id.swipeRefreshLayout)SwipeRefreshLayout mSwipeRefreshLayout;
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { //这里写你请求最新数据的操作 }});上拉加载更多
先增加一个类,重写onScrolled方法,直接拷贝即可,不用修改
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener { private int previousTotal = 0; private boolean loading = true; int firstVisibleItem, visibleItemCount, totalItemCount; private int currentPage = 1; private LinearLayoutManager mLinearLayoutManager; public EndlessRecyclerOnScrollListener( LinearLayoutManager linearLayoutManager) { this.mLinearLayoutManager = linearLayoutManager; } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); visibleItemCount = recyclerView.getChildCount(); totalItemCount = mLinearLayoutManager.getItemCount(); firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition(); if (loading) { if (totalItemCount > previousTotal) { loading = false; previousTotal = totalItemCount; } } if (!loading && (totalItemCount - visibleItemCount) <= firstVisibleItem) { currentPage++; onLoadMore(currentPage); loading = true; } } public abstract void onLoadMore(int currentPage);}使用
mRecyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(linearLayoutManager) { @Override public void onLoadMore(int currentPage) { //这里是你请求历史数据的操作 }});
至于真正的请求数据的业务,我放在了下一篇文章中,下一篇才是重中之重,我会拿开源中国的开源资讯举例,带你了解真实的业务流程。
阅读全文
0 0
- 3秒钟不懂你砍我:RecyclerView下拉刷新和上拉加载更多
- 3秒钟不懂你砍我:RecyclerView下拉刷新和上拉加载更多(开源中国List业务流程全解析)
- RecyclerView 下拉刷新上拉加载更多
- RecyclerView 下拉刷新上拉加载更多
- RecyclerView 下拉刷新、上拉加载更多
- RecyclerView 下拉刷新上拉加载更多
- RecyclerView上拉刷新,下拉加载更多
- RecyclerView 下拉刷新上拉加载更多
- RecyclerView上拉加载更多,下拉刷新
- RecyclerView实现下拉刷新和上拉加载更多
- RecyclerView下拉刷新和上拉加载更多
- SwipeRefreshLayout + RecyclerView 实现 上拉刷新 和 下拉加载更多
- RecyclerView 添加下拉刷新和上拉加载更多
- RecyclerView实现下拉刷新和上拉加载更多
- RecyclerView添加下拉刷新和上拉加载更多
- RecyclerView封装--添加下拉刷新和上拉加载更多
- Android RecyclerView下拉刷新和上拉加载更多
- Android RecyclerView下拉刷新和上拉加载更多
- angular2路由path不能传递参数的问题
- 康娜的糖果
- python 实现冒泡排序
- 环信即时通讯2.x升级到3.x注意细节
- for循环语句计算8+88+888+...前10项之和(作业)
- 3秒钟不懂你砍我:RecyclerView下拉刷新和上拉加载更多
- php 安全
- HDOJ 3020 找规律
- maven搭建项目
- ZOJ3826(Hierarchical Notation)
- log4j使用方法
- CSS 多元素选择器
- Docker容器通过独立IP暴露给局域网的方法
- 康娜的幸运数字