先导入import
之后关联
布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/pull"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.constraint.ConstraintLayout>
操作
pull.setMode(PullToRefreshListView.Mode.BOTH);
pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
getServerData();
handler.postDelayed(new Runnable() {
@Override
public void run() {
pull.onRefreshComplete();
}
}, 2000);
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
getServerData();
handler.postDelayed(new Runnable() {
@Override
public void run() {
pull.onRefreshComplete();
}
}, 2000);
}
});