当前位置:网站首页>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
边栏推荐
- Please help me see what this is, mysql5 5. Thanks
- Plato Farm-以柏拉图为目标的农场元宇宙游戏
- Pagoda panel command line help tutorial (including resetting password)
- BUUCTF WEB [BUUCTF 2018]Online Tool
- Stm32cubeprogrammer basic instructions
- Kubernetes 入门教程
- One way ANOVA of SPSS
- worder字体网页字体对照表
- C#,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码
- 远程桌面之终端服务器超出了最大允许连接数解决
猜你喜欢
Qt绘制图像
Fastjson 2 来了,性能继续提升,还能再战十年
【vulnhub靶场】-dc2
Resolve disagrees about version of symbol device_ create
Idea database navigator plug-in
A graphic designer's fantasy world | ones characters
In idea Solution to the problem of garbled code in Chinese display of properties file
31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
Unlock openharmony technology day! The annual event is about to open!
Qt绘制文字
随机推荐
编程辅助工具推荐:图片工具snipaste
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
BUUCTF WEB [GXYCTF2019]禁止套娃
Lesson 25 static member variables of classes
MySQL function - recursive function
A graphic designer's fantasy world | ones characters
数组---
洛谷P3236 [HNOI2014]画框 题解
Idea database navigator plug-in
On using go language to create websocket service
使用Source Insight查看编辑源代码
SQL 练习(一)
Metalama简介4.使用Fabric操作项目或命名空间
Web17——EL与JSTL的使用
Introduction to metalama 4 Use fabric to manipulate items or namespaces
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)
甲辰篇 創世紀《「內元宇宙」聯載》
力扣刷题之完全二叉树的节点个数
Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years
BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此