Problem with Next Button

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Problem with Next Button

Postby vaishumol » Sun Jan 03, 2010 6:43 am

Hi friends,

I am new to android. Right now im working with some sample applications using database. My application goes like this :

Having some contact names and number in DB. And displaying 10 names per each page. And having a next button which used to display another 10 names while clicking on. While launching the application i can display the first 10 names properly. When i click the next button it showing the same first 10 names in list.

How to show the another 10 names and further names while clicking hre next button.?

Here is my Query :
return mDb.rawQuery("SELECT contact_name FROM contacts LIMIT 10", null);

Please help me guys. :)

Thanks in advance. :)
Experienced Developer
Experienced Developer
Posts: 74
Joined: Sun Jan 03, 2010 6:33 am


Postby jwei512 » Sun Jan 03, 2010 11:13 pm

Well the problem is with your query...

SELECT contact_name FROM contacts LIMIT 10

Will always return the first 10 entries in your database. You would need to generate your queries on the fly, based off of how many times the user presses the "Next" button, and the easiest way to do this is probably by row id... for instance your query would looking something like:

SELECT contact_name FROM contacts WHERE _id >= 0 && id < 10;

And if the user presses "Next" your query will become:

SELECT contact_name FROM contacts WHERE _id >= 10 && id < 20;

Make sense?
- jwei
Examples, Code, and Tutorials
Senior Developer
Senior Developer
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby matrix » Tue Jan 05, 2010 3:20 am

Not 100% sure as no one has helped me with my db questions but I would do something like:

SELECT contact_name FROM contacts LIMIT "+startcount+", 10

Increment the startcount for each next ( 0, 10, 20, 30. .. .. ) this would be like :

SELECT contact_name FROM contacts LIMIT 0, 10 (first 10 records)
SELECT contact_name FROM contacts LIMIT 10, 10 (second 10 records)

This is assuming sql is sql. I would also us a do while startcount is less than the total record count. This is standard pagination in web programming. Need help myself on the Java DB stuff. Chime in guys if right or wrong.
Posts: 4
Joined: Tue Dec 22, 2009 5:07 am
Location: IN

Postby hardcoras » Tue Jan 05, 2010 3:23 pm

I don't use DB in Android. But if i had a problem like yours, i would do the same.
Adding offset and limit to a sql query is the right way for pagination.
Experienced Developer
Experienced Developer
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia


Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 2 guests