当前位置:网站首页>BaseRecyclerViewAdapterHelper 实现下拉刷新和上拉加载
BaseRecyclerViewAdapterHelper 实现下拉刷新和上拉加载
2022-04-23 12:36:00 【张雨东】
package com.jswjw.CharacterClient.teacher.home.activity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jswjw.CharacterClient.R;
import com.jswjw.CharacterClient.base.SimpleJsonCallBack;
import com.jswjw.CharacterClient.config.Constant;
import com.jswjw.CharacterClient.config.HttpConfig;
import com.jswjw.CharacterClient.teacher.examinedata.adapter.ExamineDataExpandAdapter;
import com.jswjw.CharacterClient.teacher.model.ExamineDataEntity;
import com.jswjw.CharacterClient.util.SPUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import butterknife.BindView;
import butterknife.ButterKnife;
public class TestActivity extends AppCompatActivity {
@BindView(R.id.recycleView)
RecyclerView recyclerView;
@BindView(R.id.swipeRefreshLayout)
SwipeRefreshLayout swipeRefreshLayout;
private ExamineDataExpandAdapter adapter;
private int pageIndex = 1;
private int current;
private int total;
private boolean isRefresh;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
ButterKnife.bind(this);
initView();
}
private void initView() {
adapter = new ExamineDataExpandAdapter(null, this);
//创建布局管理
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
adapter.bindToRecyclerView(recyclerView);
requestData();
adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
@Override
public void onLoadMoreRequested() {
if (current >= total) {
adapter.loadMoreEnd();
} else {
pageIndex++;
requestData();
}
}
}, recyclerView);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
pageIndex = 1;
requestData();
isRefresh = true;
}
});
}
public void requestData() {
OkGo.<ExamineDataEntity>post(HttpConfig.BASEURL + HttpConfig.TeacherUrl.USERLIST).tag(this)
.params(Constant.USER_FLOW, SPUtil.getUserFlow())
.params(Constant.DEPTFLOW, SPUtil.getUserInfo().deptFlow)
.params(Constant.PAGEINDEX, pageIndex)
.params(Constant.PAGESIZE, 10)//response.body().doctorList;
.execute(new SimpleJsonCallBack<ExamineDataEntity>() {
@Override
public void onSuccess(Response<ExamineDataEntity> response) {
total = response.body().dataCount;
if (isRefresh){
adapter.replaceData(response.body().doctorList);
isRefresh = false;
swipeRefreshLayout.setRefreshing(false);
}else {
adapter.addData(response.body().doctorList);
}
current = adapter.getData().size();
adapter.loadMoreComplete();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".teacher.home.activity.TestActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
版权声明
本文为[张雨东]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_26500807/article/details/124293597
边栏推荐
- PHP generates JSON to process Chinese
- A graphic designer's fantasy world | ones characters
- 洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
- Resolve disagrees about version of symbol device_ create
- Stacks and queues a
- Xinwangda announced that the price of battery products had been increased, and the investment of "weixiaoli" exceeded 1 billion
- Next. JS static data generation and server-side rendering
- How to switch PHP version in Windows 2008 system
- Lesson 26 static member functions of classes
- SynchronousQueue 源码解析
猜你喜欢

电脑系统卡如何解决?

Everything can be expected in the future | one 2022 campus recruitment officially opened
![[redis series] redis learning 13. Redis often asks simple interview questions](/img/4c/2440af6daa26a0ca6cb64f32bf138e.png)
[redis series] redis learning 13. Redis often asks simple interview questions
![[daily question] chessboard question](/img/70/54a924d07c935965e54b96d9b07278.png)
[daily question] chessboard question

Realize several "Postures" in which a box is horizontally and vertically centered in the parent box

Bert base Chinese Download (SMART)

大家帮我看一下这是啥情况,MySQL5.5的。谢了

为什么要有包装类,顺便说一说基本数据类型、包装类、String类该如何转换?

Qt进程间通信

宝塔面板命令行帮助教程(包含重置密码)
随机推荐
一个平面设计师的异想世界|ONES 人物
How to prevent the website from being hacked and tampered with
Buuctf Web [gxyctf2019] no dolls
没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
Array---
flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
Symmetric encryption, certificate encryption
Resolve disagrees about version of symbol device_ create
Web17 -- use of El and JSTL
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
[unity note] basic lighting in l4unity
SynchronousQueue 源码解析
BUUCTF WEB [BJDCTF2020]The mystery of ip
远程桌面之终端服务器超出了最大允许连接数解决
How much does software testing help reduce program bugs?
mysql中 innoDB执行过程分析
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
【Redis 系列】redis 学习十三,Redis 常问简单面试题
leetcode:437. 路径总和 III【dfs 选还是不选?】
QT draw image