上拉刷新下拉加载(实现代码)

一、导依赖

implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'
二、Xml布局
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refresh"
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/mRecyclerView_two"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>

<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content"></com.scwang.smartrefresh.layout.footer.ClassicsFooter>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
三、代码中
private RecyclerView mRecyclerView_two;
private SmartRefreshLayout refresh;
private List meiNvList = new ArrayList<>();
private MeiNvAdapter meiNvAdapter;
private int a;

@Override
protected void initView(View inflate) {
mPersenter.loginMeiNvPre("http://gank.io/api/");
mRecyclerView_two = (RecyclerView) inflate.findViewById(R.id.mRecyclerView_two);
refresh = (SmartRefreshLayout) inflate.findViewById(R.id.refresh);
mRecyclerView_two.setLayoutManager(new GridLayoutManager(getContext(),2));
mRecyclerView_two.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState > 0) {
((MainActivity) getActivity()).findViewById(R.id.tabbar).setVisibility(View.GONE);
} else {
((MainActivity) getActivity()).findViewById(R.id.tabbar).setVisibility(View.VISIBLE);

}

}

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});
refresh.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
meiNvList.clear();
mPersenter.loginMeiNvPre("http://gank.io/api/data/福利/20/1");
refreshlayout.finishRefresh();
}
});
refresh.setOnLoadmoreListener(new OnLoadmoreListener() {
@Override
public void onLoadmore(RefreshLayout refreshlayout) {


a++;
mPersenter.loginMeiNvPre("http://gank.io/api/data/福利/20/" + a);
refreshlayout.finishLoadmore();

}
});
}

这个只写了下拉加载,上拉刷新没有写,但是确实同理,你自己仔细看看代码就会懂了!!!

猜你喜欢

转载自blog.csdn.net/qq_42749901/article/details/81529988