当前位置:网站首页>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
边栏推荐
- 为什么要有包装类,顺便说一说基本数据类型、包装类、String类该如何转换?
- Bert base Chinese Download (SMART)
- [redis series] redis learning 13. Redis often asks simple interview questions
- Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
- box-sizing
- How much does software testing help reduce program bugs?
- 洛谷P3236 [HNOI2014]画框 题解
- Qt进程间通信
- 一个平面设计师的异想世界|ONES 人物
- Xinwangda announced that the price of battery products had been increased, and the investment of "weixiaoli" exceeded 1 billion
猜你喜欢

Qt一个进程运行另一个进程

基于卷积神经网络的遥感影像分类识别系统

【每日一题】棋盘问题

Pagoda panel command line help tutorial (including resetting password)

Resolve disagrees about version of symbol device_ create

31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...

Metalama简介4.使用Fabric操作项目或命名空间

在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决

【Redis 系列】redis 学习十三,Redis 常问简单面试题

Plato farm - a game of farm metauniverse with Plato as the goal
随机推荐
Pre competition practice of TIANTI competition
Windows2008系统如何切换PHP版本
flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
MySQL function - recursive function
Web17——EL与JSTL的使用
BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
程序员如何用130行代码敲定核酸统计
Qt绘制文字
Markdown语法学习
关于使用Go语言创建WebSocket服务浅谈
How to solve the computer system card?
实现一个盒子在父盒子中水平垂直居中的几种“姿势”
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
leetcode:437. 路径总和 III【dfs 选还是不选?】
洛谷P3236 [HNOI2014]画框 题解
为什么要有包装类,顺便说一说基本数据类型、包装类、String类该如何转换?
网络信息安全之零信任
[wechat applet] Z-index is invalid
【每日一题】棋盘问题