当前位置:网站首页>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
边栏推荐
- Array---
- 解锁OpenHarmony技术日!年度盛会,即将揭幕!
- Introduction to kubernetes
- ZigBee CC2530 minimum system and register configuration (1)
- 电脑系统卡如何解决?
- 风尚云网学习-input属性总结
- 风尚云网学习-h5的input:type属性的image属性
- Jiachen chapter Genesis "inner universe" joint Edition
- I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
- Metalama简介4.使用Fabric操作项目或命名空间
猜你喜欢
One way ANOVA of SPSS
Xinwangda announced that the price of battery products had been increased, and the investment of "weixiaoli" exceeded 1 billion
Recommended programming AIDS: picture tool snipaste
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
SSL证书退款说明
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
Can I take the CPDA data analyst certificate for 0 foundation
Please help me see what this is, mysql5 5. Thanks
传统企业如何应对数字化转型?这些书给你答案
随机推荐
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
How do traditional enterprises cope with digital transformation? These books give you the answer
Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
S2-062 远程命令执行漏洞复现(cve-2021-31805)
c# 设置logo图标和快捷方式的图标
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Markdown语法学习
CGC: contractual graph clustering for community detection and tracking
Please help me see what this is, mysql5 5. Thanks
BUUCTF WEB [BUUCTF 2018]Online Tool
flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
Labels and paths
[daily question] chessboard question
传统企业如何应对数字化转型?这些书给你答案
PHP generates JSON to process Chinese
天梯赛赛前练习
[csnote] ER diagram
STM32 control stepper motor (ULN2003 + 28byj)
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
QT redraw events and cuts