private boolean isErr = false; //是否加载错误
private int TOTAL_COUNTER = 16; //一共模拟加载16条数据,所有的数据总数
private int mCurrentCounter = 6; //当前的数据总数,因为第一次默认加载6个
//1.上拉加载
mImgDetailsAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
@Override public void onLoadMoreRequested() {
imgDetailRecycler.postDelayed(new Runnable() {
@Override
public void run() {
if (mCurrentCounter >= TOTAL_COUNTER) {
//数据全部加载完毕
mImgDetailsAdapter.loadMoreEnd();
} else {
if (!isErr) {
//成功获取更多数据
mImgDetailsAdapter.addData(getServerDatas());
mCurrentCounter = mImgDetailsAdapter.getData().size();
mImgDetailsAdapter.loadMoreComplete();
} else {
//获取更多数据失败 PullToRefreshUseActivity
isErr = true;
Toast.makeText(ImgDetailsActivity.this, "获取更多数据失败", Toast.LENGTH_LONG).show();
mImgDetailsAdapter.loadMoreFail();
}
}
}
}, 1500);
}
}, imgDetailRecycler);
//模拟从服务器获取数据
public List<ImgDetails> getServerDatas(){
ImgDetails details;
List<ImgDetails> newDatas = new ArrayList<ImgDetails>();
//for (int i = 0; i < 1; i++) {
details = new ImgDetails();
details.setUrl("http://t1.hxzdhn.com/uploads/tu/sm/201601/18/35.jpg");
newDatas.add(details);
//}
return newDatas;
}