1. 程式人生 > >PullToRefresh實現上下拉重新整理

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) {
                //下拉載入
               
            }
        });