PullToRefresh是一套实现非常好的下拉刷新库,它支持:
1.ListView
2.ExpandableListView
3.GridView
4.WebView
使用步骤:
一、
将PullToRefreshlibrary 导入到android studio中(import module),
更改pullToRefreshlibrary的build.gradle
compileSdkVersion 23
buildToolsVersion "24.0.1"(跟你项目的build.gradle一致)
二、修改过时的MathFloor方法
三、在你的app中引用
例如:
<com.handmark.pulltorefresh.library.PullToRefreshGridView android:layout_marginLeft="12dp" android:id="@+id/pullgv_tuijian_jingcai" android:layout_below="@id/lin_hot" android:layout_width="match_parent" android:layout_height="match_parent" android:horizontalSpacing="1dp" android:verticalSpacing="1dp" android:numColumns="3"> </com.handmark.pulltorefresh.library.PullToRefreshGridView>
2、在MainActivity.class中
private PullToRefreshGridView myPullToRefreshGridView;
//初始化控件 public void InitView() { myPullToRefreshGridView = (PullToRefreshGridView) view.findViewById(R.id.pullgv_tuijian_jingcai); myPullToRefreshGridView.setMode(PullToRefreshBase.Mode.BOTH);//设置模式能上下拉刷新 }
三、
重写setOnRefreshListener方法。
myPullToRefreshGridView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<GridView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) { GridView_jingcai(ContanPath.PATH_JINGCAI +1); } @Override public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) { GridView_jingcai(ContanPath.PATH_JINGCAI +(++i)); } });
4、实现分页加载,改变页面索引,并用
adapter.notifyDataSetChanged();