編輯:關於Android編程
1,一共多少條數據
select count(*) from blacktb;
性能低下
原因: sql解析器先查詢數據字典,把*轉成所有的列名和列的類型
然後把每行數據提取出來
最後統計多少行數據
select count(常量) from blacktb;
高性能的查詢
不需要每行的記錄,只需要行數
2,指定每頁顯示多少條
需求制定每頁行數 如: 20
3,計算出共多少頁
int pages = (int)Math.ceil(201 * 1.0 / 20); // 10.05
4,取每頁的信息 3頁的數據
select * from blacktb limit 取多少條 offset 從哪條數據;
select * from blacktb limit 行的起始位置 , 多少條數據;
如:取第3頁 PageNumber每頁顯示多少條數據
select * from blacktb limit (3 - 1)*PageNumber,PageNumber
/**
* @return 總數據個數
*/
public int getTotalRows() {
SQLiteDatabase database = blackDB.getReadableDatabase();
Cursor cursor = database.rawQuery("select count(1) from "
+ BlackTable.BLACKTABLE, null);
cursor.moveToNext();
// 總行數
int totalRows = cursor.getInt(0);
cursor.close();// 關閉游標
return totalRows;
}
/**
* @param currentPage
* 當前頁的頁碼
* @param perPage
* 每頁顯示多少條數據
* @return 當前頁的數據
*/
public List getPageDatas(int currentPage, int perPage) {
List datas = new ArrayList();
SQLiteDatabase database = blackDB.getReadableDatabase();
// 獲取blacktb的所有數據游標 (2 + 3) + ""
Cursor cursor = database.rawQuery("select " + BlackTable.PHONE + ","
+ BlackTable.MODE + " from " + BlackTable.BLACKTABLE
+ " limit ?,? ", new String[] {((currentPage - 1) * perPage) + "",perPage + ""});
while (cursor.moveToNext()) {
// 有數據,數據封裝
BlackBean bean = new BlackBean();
// 封裝黑名單號碼
bean.setPhone(cursor.getString(0));
// 封裝攔截模式
bean.setMode(cursor.getInt(1));
// 添加數據到集合中
datas.add(bean);
}
cursor.close();// 關閉游標
database.close();// 關閉數據庫
return datas;
}
/**
* @param perPage
* 指定每頁顯示多少條數據
* @return 總頁數
*/
public int getTotalPages(int perPage) {
int totalRows = getTotalRows();
// 計算出多少頁,采用ceil函數,返回不小於該數的最小整數 如 :6.1 返回7.0
int totalPages = (int) Math.ceil(totalRows * 1.0 / perPage);
return totalPages;
}
android自定義view 模仿win10進度條
先上預覽圖:流程1.一個勻速圓周運動的點 2.多個勻速圓周運動的點 3.多個圓周運動的點,速度由快到慢 4.點與點之間的間距線性減少,動畫的最後合為一個點 5.為了讓動畫
RecyclerView下拉刷新上拉加載(一)
前幾篇文章講過listview的自定義下拉刷新上拉加載,最近一直考慮再來個RecyclerView的下拉刷新和上拉加載,畢竟RecyclerView使用的越來越多了,扒了
(一) Android WebView是什麼?
1.Android WebView 一些基本概念 在 Android 手機中內置了一款高性能 webkit 內核浏覽器,在 SDK 中封裝為一個叫做 WebVie
Android中ViewFlipper的使用及設置動畫效果實例詳解
本文實例講述了Android中ViewFlipper的使用及設置動畫效果。分享給大家供大家參考,具體如下:說到左右滑動,其實實現左右滑動的方式很多,有ViewPaer,自