首先就是导入依赖
compile 'com.jwenfeng.pulltorefresh:library:1.0.3'
在所需要的类中或者Fragment中使用
pullToRefreshLayout.setRefreshListener(new BaseRefreshListener() {
@Override
public void refresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 结束刷新
pullToRefreshLayout.finishRefresh();
}
}, 2000);
}
@Override
public void loadMore() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 结束加载更多
pullToRefreshLayout.finishLoadMore();
}
}, 2000);
}
});
XML
<?xml version="1.0" encoding="utf-8"?>
<com.jwenfeng.library.pulltorefresh.PullToRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 内容控件 有且只能有一个 -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
</com.jwenfeng.library.pulltorefresh.PullToRefreshLayout>