首先导入依赖
//SmartRefreshLayout的依赖
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-6'
在需要刷新的写入控件
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/smartrefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/xrecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
在MainActivity中初始化然后写入方法
smartrefresh.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
results.clear();
page =1;
shoppingPresenter.load(page);
shopAdapter.notifyDataSetChanged();
refreshlayout.finishRefresh();
}
});
smartrefresh.setOnLoadmoreListener(new OnLoadmoreListener() {
@Override
public void onLoadmore(RefreshLayout refreshlayout) {
page ++;
shoppingPresenter.load(page);
shopAdapter.notifyDataSetChanged();
refreshlayout.finishLoadmore();
}
});