当前位置:网站首页>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
边栏推荐
- Resolve disagrees about version of symbol device_ create
- QT double buffer drawing
- Qt绘制文字
- Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
- How to switch PHP version in Windows 2008 system
- Number of nodes of complete binary tree
- 对话PostgreSQL作者Bruce:“转行”是为了更好地前行
- 编程辅助工具推荐:图片工具snipaste
- Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
- Aviation core technology sharing | overview of safety characteristics of acm32 MCU
猜你喜欢
AI 视频云 VS 窄带高清,谁是视频时代的宠儿
Worder font page font comparison table
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Pre competition practice of TIANTI competition
宝塔面板命令行帮助教程(包含重置密码)
Recommended programming AIDS: picture tool snipaste
Unlock openharmony technology day! The annual event is about to open!
mysql中 innoDB执行过程分析
box-sizing
Labels and paths
随机推荐
Pre competition practice of TIANTI competition
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
Pagoda panel command line help tutorial (including resetting password)
QT draw text
Next. JS static data generation and server-side rendering
Everything can be expected in the future | one 2022 campus recruitment officially opened
一个平面设计师的异想世界|ONES 人物
数组---
Bert base Chinese Download (SMART)
Plato farm - a game of farm metauniverse with Plato as the goal
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
C#,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码
A graphic designer's fantasy world | ones characters
Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
SPSS之单因素方差分析
QT redraw events and cuts
IDEA设置版权信息
标签与路径
天梯赛赛前练习
Metalama简介4.使用Fabric操作项目或命名空间