布局的时候需要手动Copy
属性
//第三步:设置属性
// 设置刷新的模式:常用的有三种
// PullToRefreshBase.Mode.BOTH //上下拉刷新都可以
// PullToRefreshBase.Mode.PULL_FROM_START //只允许下拉刷新
// PullToRefreshBase.Mode.PULL_FROM_END //只允许上拉加载
listview.setMode(PullToRefreshBase.Mode.BOTH);
//第四步:是否允许刷新时滑动
listview.setScrollingWhileRefreshingEnabled(true);
//选择第二个方法
listView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
//下拉刷新
@Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
//请求网络
HTTPTitle.getAsynask(bannerUrl, new HTTPTitle.CallBackA() {
@Override
public void getData(String s) {
//请求网络
//把集合2的数据给集合1
//刷新适配器
//刷新控件
Gson gson=new Gson();
JsonBean jsonBean = gson.fromJson(s, JsonBean.class);
ArrayList<Two> result1 = jsonBean.getResult();
result.addAll(result1);
//刷新控件
listView.onRefreshComplete();
}
});
}
//上拉加载
@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
HTTPTitle.getAsynask(bannerUrl, new HTTPTitle.CallBackA() {
@Override
public void getData(String s) {
Gson gson=new Gson();
JsonBean jsonBean = gson.fromJson(s, JsonBean.class);
ArrayList<Two> result3 = jsonBean.getResult();
result.addAll(result3);
//刷新控件
listView.onRefreshComplete();
}
});
}
});