Android实现ListView分页显示@阮世耀
定义翻页的变量,用于List遍历
因为List遍历下标从0开始,每页显示3条所以定义2,每页显示10条就定义9
int leijia = 2;
int chushihua = 0;
下一页的按钮点击事件
xiayiyeBtn是button控件的ID:
xiayiyeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
leijia = leijia + 3;
chushihua = chushihua + 3;
initData();
}
});
加载数据
private void initData() {
List<FaceContrastBean> listType;
List<FaceContrastBean> typeList = new ArrayList<>();
listView.setAdapter(null);
String selOrgUrl = WorkConfig.getGzramaUrl() + "user/getFaceContrastList";
FormBody body = new FormBody.Builder()
.add("proId",proId)
.add("name",name)
.add("startDay",startDayText)
.add("endDay",endDayText)
.build();
String result = service.httpPostNoToken(selOrgUrl, body);
Message msg=new Message();
if (!StringHelper.isEmptyAndNull(result)) {
JSONObject jsonObject = JsonHelper.jsonStrToJsonObj(result);
String status = jsonObject.getString("resMsg");
if ("success".equals(status)) {
listType = JsonHelper.jsonArrToBeanList(jsonObject.getJSONArray("obj"), FaceContrastBean.class);
for ( int i = chushihua ; i<listType.size();i++){
if(i > leijia){
break;
}
FaceContrastBean bean = new FaceContrastBean();
String no = String.valueOf(i+1);
bean.setId(no);
bean.setName(listType.get(i).getName());
bean.setIdNumber(listType.get(i).getIdNumber());
bean.setCountDay(listType.get(i).getCountDay());
bean.setJiaBanDay(listType.get(i).getJiaBanDay());
bean.setQueQinDay(listType.get(i).getQueQinDay());
bean.setCurrentCountDAY(listType.get(i).getCurrentCountDAY());
bean.setProId(listType.get(i).getProId());
bean.setAuditStatusCount(listType.get(i).getAuditStatusCount());
typeList.add(bean);
}
msg.what=1;
msg.obj=typeList;
safeguardingHandler.sendMessage(msg);
}else{
XToastUtils.error("查询不到符合条件的数据");
}
}else{
XToastUtils.error("result返回值为空");
}
|