Reputation: 14387
I am trying to fetch sms messages from inbox, sent items and drafts. I would like to do a pagination for my list view for that it's imperative that I fetch records in pages/chunks.
I am not familiar with sqlite which is the database I understand android use to store the data. Can someone tell me how can I restrict the number of records I am fetching by using contentResolver.query?
Also what is the way to pull the sqlite database file onto my machine and browse/query it locally to experiment or see data on my machine?
Are there any other better ways to implement pagination in android??
Thanks
Upvotes: 5
Views: 7238
Reputation: 36806
According to the Sqlite website, you can use a LIMIT ... OFFSET ...
clause in your query:
Upvotes: 8
Reputation: 6591
For anyone stumbling across this answer looking for a way to use a LIMIT
clause with an OFFSET
, I found out from this bug that Android uses the following regex to parse the limit clause of a query:
In framework/base/core/java/android/database/sqlite/SQLiteQueryBuilder.java:
LIMIT clause is checked with following sLimitPattern.
private static final Pattern sLimitPattern = Pattern.compile("\\s*\\d+\\s*(,\\s*\\d+\\s*)?");
Note that the regex does accept the format offsetNumber,limitNumber
even though it doesn't accept the OFFSET
statement directly.
Upvotes: 5
Reputation: 8622
There doesn't seem to be any way to limit your results from the SmsProvider
. However you shouldn't really need to, given that you use CursorAdapter
and don't try to read the contents into your own data structures. Have you tried this?
Upvotes: 1
Reputation: 11047
To pull your database for viewing, make a copy of it on the SD card and then use adp pull to get it.
Upvotes: 1