/* Fields */
private
int
pageSize
= 10;
private
int
currentPage
= 1;
private
int
maxPage
;
private
int
countRows
;
------------------------------------------------------------------------
/**
* 查询所有黑名单个数
*
@return
*/
public
int
getMaxNumber(){
int
total=0;
SQLiteDatabase db =
helper
.getWritableDatabase();
Cursor cursor = db.rawQuery(
"select * from blacknumber"
,
null
);
total=cursor.getCount();
//得到数据库有多少条记录
db.close();
return
total;
}
/**
* 获取一共有多少页的内容.
*
@param
pageSize
*
@return
*/
public
int
getTotalPage(
int
pageSize){
int
total = getMaxNumber();
if
(total%pageSize ==0){
return
total/pageSize;
}
else
{
return
total/pageSize+1;
}
}
/**
* 分页的获取黑名单号码
* currentPage 当前第几页
* PageSize 每页显示多少条数据
*
@return
*/
public
List<BlackNumberBean> getBlackNumberInfosByPage(
int
currentPage,
int
PageSize){
try
{
Thread. sleep(600);
}
catch
(InterruptedException e) {
e.printStackTrace();
}
List<BlackNumberBean> numberList=
new
ArrayList<BlackNumberBean>();
SQLiteDatabase db =
helper
.getWritableDatabase();
Cursor cursor = db.rawQuery(
"select * from blacknumber limit ? , ?"
,
new
String[] {
String. valueOf(currentPage), String.valueOf((currentPage-1)*PageSize) });
while
(cursor.moveToNext()){
BlackNumberBean numberBean=
new
BlackNumberBean();
numberBean.setId(cursor.getInt(cursor.getColumnIndex(
"id"
)));
numberBean.setNumber(cursor.getString(cursor.getColumnIndex(
"number"
)));
numberBean.setMode(cursor.getString(cursor.getColumnIndex(
"mode"
)));
numberList.add(numberBean);
}
db.close();
return
numberList;
}