仿google分页简析
1.类中成员变量解析
//当前页
private int nowpage;
//总记录数
private int countrecord;
//总页数
private int countpage;
// 当前页记录开始的位置
private int pageindex;
// 每页显示的记录数
public static final int PAGESIZE = 5;
// 索引的sum值 代表的是 google页面中最大显示页数
private int sumindex = 6;
// 开始的索引值
private int startindex;
// 结束的索引值
private int endindex;
2.分析:以下是以显示6个数页为参考
1 2 3 当前页是1
1 2 3 4 当前页是2 起始值1 未页 4
1 2 3 4 5 当前页是3 起始值1 未页 5
1 2 3 4 5 6 当前页是4 起始值1 未页 6
从上分析得知 当前页小于等于4时 起始页为1 末页=当前页+2
代码:
当当前页小于等于四时开始的索引值等于一,而结束的索引值分两种情况
if (this.nowpage <= 4) {
this.startindex = 1;
if (this.endindex > this.countpage) {
this.endindex = this.countpage;
}
this.endindex = this.nowpage + 2;
}
2 3 4 5 6 7 当前页是5 起始值是2 未页 7
3 4 5 6 7 8 当前页是6 起始值是3 未页 8
4 5 6 7 8 9 当前页是7 起始值是4 未页 9
5 6 7 8 9 10 当前页是8 起始值是5 未页 10
从上分析得知 当前页大于4时 (包括4)
当当前页大于四时开始的索引值和结束的索引值均分三种情况
if (this.nowpage > 4) {
this.startindex = this.nowpage - 3;
this.endindex = this.nowpage + 2;
if (this.endindex > this.countpage
&& this.countpage < this.sumindex) {
this.endindex = this.countpage;
this.startindex = 1;
}
if (this.countpage > this.sumindex) {
this.endindex = this.countpage;
this.startindex = this.countpage - 5;
}
}
1.类中成员变量解析
//当前页
private int nowpage;
//总记录数
private int countrecord;
//总页数
private int countpage;
// 当前页记录开始的位置
private int pageindex;
// 每页显示的记录数
public static final int PAGESIZE = 5;
// 索引的sum值 代表的是 google页面中最大显示页数
private int sumindex = 6;
// 开始的索引值
private int startindex;
// 结束的索引值
private int endindex;
2.分析:以下是以显示6个数页为参考
1 2 3 当前页是1
1 2 3 4 当前页是2 起始值1 未页 4
1 2 3 4 5 当前页是3 起始值1 未页 5
1 2 3 4 5 6 当前页是4 起始值1 未页 6
从上分析得知 当前页小于等于4时 起始页为1 末页=当前页+2
代码:
当当前页小于等于四时开始的索引值等于一,而结束的索引值分两种情况
if (this.nowpage <= 4) {
this.startindex = 1;
if (this.endindex > this.countpage) {
this.endindex = this.countpage;
}
this.endindex = this.nowpage + 2;
}
2 3 4 5 6 7 当前页是5 起始值是2 未页 7
3 4 5 6 7 8 当前页是6 起始值是3 未页 8
4 5 6 7 8 9 当前页是7 起始值是4 未页 9
5 6 7 8 9 10 当前页是8 起始值是5 未页 10
从上分析得知 当前页大于4时 (包括4)
当当前页大于四时开始的索引值和结束的索引值均分三种情况
if (this.nowpage > 4) {
this.startindex = this.nowpage - 3;
this.endindex = this.nowpage + 2;
if (this.endindex > this.countpage
&& this.countpage < this.sumindex) {
this.endindex = this.countpage;
this.startindex = 1;
}
if (this.countpage > this.sumindex) {
this.endindex = this.countpage;
this.startindex = this.countpage - 5;
}
}
213

被折叠的 条评论
为什么被折叠?



