当前位置:网站首页>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
边栏推荐
- [unity note] basic lighting in l4unity
- uni-app 原生APP-本地打包集成极光推送(JG-JPUSH)详细教程
- 解锁OpenHarmony技术日!年度盛会,即将揭幕!
- How do traditional enterprises cope with digital transformation? These books give you the answer
- How to prevent the website from being hacked and tampered with
- php生成json处理中文
- C, calculation code of parameter points of two-dimensional Bezier curve
- Aviation core technology sharing | overview of safety characteristics of acm32 MCU
- RT-thread中关键词解释及部分API
- QT draw image
猜你喜欢
QT double buffer drawing
Number of nodes of complete binary tree
Realize several "Postures" in which a box is horizontally and vertically centered in the parent box
消息队列概述
Fastjson 2 来了,性能继续提升,还能再战十年
NPDP | how can product managers not be excluded by programmers?
【vulnhub靶场】-dc2
宝塔面板命令行帮助教程(包含重置密码)
航芯技术分享 | ACM32 MCU安全特性概述
QT draw text
随机推荐
关于使用Go语言创建WebSocket服务浅谈
SQL exercise (I)
Introduction to metalama 4 Use fabric to manipulate items or namespaces
智能多线弹性云增加独立的IP地址,如何实现多线功能?
Qt绘制图像
力扣刷题之完全二叉树的节点个数
STM32CubeProgrammer基础使用说明
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
【Redis 系列】redis 学习十三,Redis 常问简单面试题
uni-app 原生APP-云打包集成极光推送(JG-JPUSH)详细教程
【csnote】ER图
一个平面设计师的异想世界|ONES 人物
风尚云网学习-h5的input:type属性的image属性
BUUCTF WEB [GXYCTF2019]禁止套娃
Stacks and queues a
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
QT draw text
AD20补充笔记3—快捷键+持续更新
C, calculation code of parameter points of two-dimensional Bezier curve
The database navigator uses the default MySQL connection prompt: the server time zone value 'Ö Ð¹ ú±ê ×¼ ʱ ¼ ä’ is unrecognized or repres