当前位置:网站首页>Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
2022-04-23 12:39:00 【Zhang Yudong】
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);
// Create layout management
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>
版权声明
本文为[Zhang Yudong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231236538452.html
边栏推荐
- 基于卷积神经网络的遥感影像分类识别系统
- BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
- Buuctf Web [bjdctf2020] zjctf, but so
- 网络信息安全之零信任
- BUUCTF WEB [BUUCTF 2018]Online Tool
- box-sizing
- S2-062 远程命令执行漏洞复现(cve-2021-31805)
- Aviation core technology sharing | overview of safety characteristics of acm32 MCU
- 只是不断地建构平台,不断地收拢流量,并不能够做好产业互联网
- Plato Farm-以柏拉图为目标的农场元宇宙游戏
猜你喜欢

STM32 project transplantation: transplantation between chip projects of different models: Ze to C8

QT one process runs another

box-sizing

CGC: contractual graph clustering for community detection and tracking

Number of nodes of complete binary tree

免费试用一个月的服务器,并附上教程

SSL证书退款说明

实现一个盒子在父盒子中水平垂直居中的几种“姿势”

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

没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
随机推荐
Metalama简介4.使用Fabric操作项目或命名空间
Worder font page font comparison table
Stm32cubeprogrammer basic instructions
How to prevent the website from being hacked and tampered with
uni-app 原生APP-云打包集成极光推送(JG-JPUSH)详细教程
One way ANOVA of SPSS
S2-062 远程命令执行漏洞复现(cve-2021-31805)
leetcode:437. Path sum III [DFS selected or not selected?]
Lesson 23 temporary objects
MySQL函数-递归函数
Plato farm - a game of farm metauniverse with Plato as the goal
NPDP|产品经理如何做到不会被程序员排斥?
uni-app 原生APP-本地打包集成极光推送(JG-JPUSH)详细教程
Why is the premise of hash% length = = hash & (length-1) that length is the nth power of 2
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
How do programmers finalize nucleic acid statistics with 130 lines of code
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Xinwangda announced that the price of battery products had been increased, and the investment of "weixiaoli" exceeded 1 billion
Pre competition practice of TIANTI competition
【vulnhub靶场】-dc2