当前位置:网站首页>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
边栏推荐
猜你喜欢
风尚云网学习-h5的input:type属性的image属性
Kubernetes 入门教程
解锁OpenHarmony技术日!年度盛会,即将揭幕!
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Pre competition practice of TIANTI competition
Try the server for one month for free, and attach the tutorial
Plato farm - a game of farm metauniverse with Plato as the goal
Outsourcing for five years, abandoned
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
力扣刷题之完全二叉树的节点个数
随机推荐
Qt一个进程运行另一个进程
0基础可以考CPDA数据分析师证书吗
How do traditional enterprises cope with digital transformation? These books give you the answer
Array---
【csnote】ER图
Zigbee之CC2530最小系统及寄存器配置(1)
Markdown grammar learning
C set Logo Icon and shortcut icon
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)
Qt重绘事件与剪切
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
标签与路径
SPSS之单因素方差分析
万事有你 未来可期 | ONES 2022校园招聘正式开启
Message queuing overview
What are the forms of attack and tampering on the home page of the website
免费试用一个月的服务器,并附上教程
【微信小程序】z-index失效
31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
[redis series] redis learning 13. Redis often asks simple interview questions