//三个参数
private int pageNo = 1;
private int pageSize = 10;
private int count = 0;
//刷新
pullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
pageNo = 1;
refresh();
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
if (pageNo*pageSize < count) {
pageNo += 1;
refresh();
} else {
pullToRefreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
}
}
});
//一个方法实现
try {
JSONArray parkingArrays = response.getJSONArray("datalist");
count = response.getInt("count");
if (pageNo == 1) {
mListItems.clear();
}
if (parkingArrays != null) {
for (int i = 0; i < parkingArrays.length(); i++) {
mListItems.add(parkingArrays.getJSONObject(i));
}
localArrayAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (pullToRefreshListView.isRefreshing()) {
pullToRefreshListView.onRefreshComplete();
}
if (count <= pageNo*pageSize) {
pullToRefreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
} else {
pullToRefreshListView.setMode(PullToRefreshBase.Mode.BOTH);
}
}
使用PullToRefreshListView下拉和加载代码
最新推荐文章于 2021-02-26 08:45:38 发布