Thanks in advance.
I am developing a Car Review Application, where user can log in and displayed all the review from the Database. All the the data is being stored i
Kindly provide the logic/sample source code on how to implement the pagination if anyone has already implemented.
See CommonsWare EndlessAdapter.
Using the LIMIT
keyword from MYSQL
you can achieve pagination.
LIMIT
allows you to control the number of rows returned by query:
Example:
to show first 10 records
SELECT * FROM Student LIMIT 10 //for first time
to show rows between 10 and 20
SELECT *FROM Student LIMIT 9, 10 //after showing the records first time
LIMIT
works for SQLiteDatabase
also
You can use something like:
Page 1:
SELECT * FROM YOUR_TABLE LIMIT 20 OFFSET 0
Page 2:
SELECT * FROM YOUR_TABLE LIMIT 20 OFFSET 20
Reference: http://sqlite.org/lang_select.html
You can use the concept of Asynchronous tasks along with SimpleCursorAdapters.
"AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers."
Here's what you can do:
1) Retrieve only 1st 10/15 items in the 1st query. 2) Fire another query as a background task, while user is checking out first 10/15 items.
This will certainly make the User experience faster