1

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 in MYSQLdatabase first. I am using json to connect to the MYSQLdatabase and SQLiteDatabase. But the problem is that, after log in the application screen huge no. of data is coming from the server and it is being inserted in our SQLite Database.

After that it is being retrieved from database and displayed in the Application Screen in a list view, it is taking a longer time to displayed all the data in list view. In that case, I am using a SimpleCursorAdapter to retrieve all the data from database.

So is there any way like pagination or something like that to make the data retrieval faster. Please help me by giving some source code.

Avijit
  • 3,834
  • 4
  • 33
  • 45

3 Answers3

3

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

2

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

Scrooge
  • 86
  • 7
1

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

Bhushan
  • 6,151
  • 13
  • 58
  • 91