ListView和GridView的逻辑都是一样的。
一、建布局,注意自定义属性和设置属性
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ptr="http://schemas.android.com/apk/res-auto" 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="match_parent" android:id="@+id/listview" ptr:ptrMode="both"></com.handmark.pulltorefresh.library.PullToRefreshListView> </LinearLayout>
二、对ListView设置监听
listview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) { state=state_down; if(index>1){ index--; } jiexi(); } @Override public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) { index++; jiexi(); } });
三、设置刷新完取消图标,要放在主线程去执行
listview.onRefreshComplete();