PullToRefresh实现上下拉刷新

:下拉刷新这个功能很常见,今天就介绍基本的刷新方法

首先要导入依赖

implementation 'com.github.userswlwork:pull-to-refresh:1.0.0'

XML布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.handmark.pulltorefresh.library.PullToRefreshListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="20dp"
        android:id="@+id/listview">


    </com.handmark.pulltorefresh.library.PullToRefreshListView>


</LinearLayout>

支持上下拉刷新属性
默认是支持下拉刷新的

pull_listview.setMode(PullToRefreshBase.Mode.BOTH);

关闭上下拉刷新
如果不关闭就会一直卡在加载动画

 pull_listview.onRefreshComplete();

上下拉刷新监听

        //pull的监听,上下拉刷新
        pull_listview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> pullToRefreshBase) {
                //下拉刷新
               

            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> pullToRefreshBase) {
                //下拉加载
               
            }
        });

猜你喜欢

转载自blog.csdn.net/weixin_43807869/article/details/85012297