2014-10-19 68 views
2

我正在開發android應用程序,它使用SQLite數據庫。Sqlite獲取x行,然後下一個x行

我有ListView它使用來自數據庫的數據來顯示一個列表(見圖片)。

圖片在Base64字符串中解碼並存儲在數據庫中。我的問題是這個日誌:

10-19 16:51:36.612: W/CursorWindow(15151): Window is full: 
requested allocation 136877 bytes, free space 78836 bytes, window size 2097152 bytes 

它skypes很多幀,因爲讀取時間增長。 這是因爲我總是讀x + 10行。 月1日,它顯示的是10行,然後20,然後30,並繼續...

的解決方案,我想用的,從0-10得到行,11 - 20,21 - 30等上。如何實現這一目標?我只需要Sql查詢。

編輯:我查詢

String columns[] = {KEY_ID, KEY_NAME, KEY_RATING, KEY_CUISINE, KEY_IMAGE}; 
Cursor cursor = db.query(TABLE_RECIPES, columns, null, null, null, null, KEY_NAME, lim); 

ListView

回答

7

使用rawQuery方法,並指定限制關鍵字。

例如爲:

"SELECT * FROM myTable limit 10" <-- get the 1st 10 rows 
"SELECT * FROM myTable limit 10, 20" <-- get the 2nd 10 rows between 10 and 20, etc 

這應該讓你開始。

+0

此外,您還可以使用查詢(),您的極限參數設置這樣的「10,20」的字符串。 :) – 2014-10-19 20:15:13

+0

'「SELECT * FROM myTable limit 10,20」' 這會給從11到30的20行。 – 2017-10-04 13:13:54

+0

請更正您的評論 – 2017-10-04 13:14:26

0

我試圖回答上面,結果是:

"SELECT * FROM myTable limit 10" <-- Got the first 10 rows 
"SELECT * FROM myTable limit 10, 20" <-- Got the first 20 rows ! 

所以答案上面並沒有爲我工作,什麼工作對我來說是這樣的:

這是我的表:

table

爲了得到第10

select * from quran_text where sura = 2 limit 0, 10 

first10

二10:

select * from quran_text where sura = 2 limit 10, 10 

second10

第三10:

select * from quran_text where sura = 2 limit 20, 10 

third10

在圖片中它只顯示了5個記錄的空間,但它得到了正確的結果。

所以使其爲圖案:

得到它爲第一10此處X = 1;

Java創建查詢:

String query = "select * from quran_text where sura = 2 limit "+((X-1)*10)+", 10"; 
相關問題