user669444
user669444

Reputation: 133

Listview showing lot of content from database

I have a huge database containing a lot of items. All text. I am able to query it and show it in a ListView using an adapter. Since the database is huge (over 2000 items), it takes a lot of time for the list to show up initially. I was wondering if there was a way in which I could query the DB little by little and show the items in the listview. As atmost only 15 items will be shown on screen, there seems to be no point in getting the whole database queried. Can someone point me on how to go ahead with this ?

Upvotes: 0

Views: 91

Answers (1)

Caner
Caner

Reputation: 59258

You can use SQL LIMIT to limit the rows you fetch from database:

This will display the first 5 results from the database:

SELECT * FROM `your_table` LIMIT 0, 5

To get the 2nd 5 results for second page, use this, it will show records 6, 7, 8, 9, and 10:

SELECT * FROM `your_table` LIMIT 5, 5 

Upvotes: 1

Related Questions