/** 查询全部的黑名单号码 */ public List<BlackNumberInfo> findAll() { // 得到可读的数据库 SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.query("blackinfo", new String[] {"number", "mode"}, null, null, null, null, null); List<BlackNumberInfo> blackNumberInfos = new ArrayList<BlackNumberInfo>(); while (cursor.moveToNext()) { BlackNumberInfo info = new BlackNumberInfo(); String number = cursor.getString(0); String mode = cursor.getString(1); info.setMode(mode); info.setNumber(number); blackNumberInfos.add(info); } cursor.close(); db.close(); SystemClock.sleep(3000); return blackNumberInfos; }
/** * 分批加载数据 * * @param startIndex 从哪个位置开始加载数据 * @param maxCount 最多加载几条数据 */ public List<BlackNumberInfo> findPart2(int startIndex, int maxCount) { // 得到可读的数据库 SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.rawQuery( "select number,mode from blackinfo order by _id desc limit ? offset ?", new String[] {String.valueOf(maxCount), String.valueOf(startIndex)}); List<BlackNumberInfo> blackNumberInfos = new ArrayList<BlackNumberInfo>(); while (cursor.moveToNext()) { BlackNumberInfo info = new BlackNumberInfo(); String number = cursor.getString(0); String mode = cursor.getString(1); info.setMode(mode); info.setNumber(number); blackNumberInfos.add(info); } cursor.close(); db.close(); SystemClock.sleep(1000); return blackNumberInfos; }
/** * 分页查询数据库的记录 * * @param pagenumber 第几页,页码 从第0页开始 * @param pagesize 每一个页面的大小 */ public List<BlackNumberInfo> findPart(int pagenumber, int pagesize) { // 得到可读的数据库 SQLiteDatabase db = helper.getReadableDatabase(); Cursor cursor = db.rawQuery( "select number,mode from blackinfo limit ? offset ?", new String[] {String.valueOf(pagesize), String.valueOf(pagesize * pagenumber)}); List<BlackNumberInfo> blackNumberInfos = new ArrayList<BlackNumberInfo>(); while (cursor.moveToNext()) { BlackNumberInfo info = new BlackNumberInfo(); String number = cursor.getString(0); String mode = cursor.getString(1); info.setMode(mode); info.setNumber(number); blackNumberInfos.add(info); } cursor.close(); db.close(); SystemClock.sleep(30); return blackNumberInfos; }