首页 > 代码库 > 翻页工具类

翻页工具类

简洁明了,一直在用的一个翻页类.  本地数据翻页的话,可以使用.

效果:

界面很简单,不再浪费感情.

源码如下:

/**
 * 
* @Title: Page.java
* @Package fay.frame.tools
* @Description: 翻页工具
* @author : Fay
* @date 2014-6-27 下午3:14:31
* @version V1.0
 */
public class Page {
int total = 100;
int curPage = 1;
int maxPage = 0;
int perPageNum = 10;
int startIndex = 0;
int endIndex = 0;


public void setTotal(int total) {
this.total = total;
}


public void setPerPageNum(int perPageNum) {
this.perPageNum = perPageNum;
}


public Page() {


}


public Page(int _total, int _perPageNum) {
total = _total;
perPageNum = _perPageNum;
if (total % perPageNum == 0) {
maxPage = total / perPageNum;
} else {
maxPage = total / perPageNum + 1;
}
}


public void toPage(int index) {
if (index < 1) {
index = 1;
} else if (index > maxPage) {
index = maxPage;
}
curPage = index;
startIndex = (curPage - 1) * perPageNum + 1;
endIndex = startIndex + perPageNum - 1;
if (endIndex > total) {
endIndex = total;
startIndex = endIndex - perPageNum + 1;
}
}


public void prePage() {
toPage(curPage--);
}


public void nextPage() {
toPage(curPage++);
}
}