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

首先要导入依赖

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

布局

<LinearLayout  ns: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(PullToRefresh .Mode.BOTH);

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

 pull_listview.onRefreshComplete();

上下拉刷新监听

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

            }

            @Override
            public void onPullUpToRefresh(PullToRefresh <ListView> pullToRefresh ) {
                //下拉加载
               
            }
        });
收藏 打印