简体   繁体   中英

Next/Previous Record (Database Android)

在此处输入图片说明

I have some records in SQLite Database. With more than 2 records. I want to go to for example

  • id:1 to id:2 when press next and
    • id:2 to id:1 when press previous.

To get the next record (if any):

SELECT *
FROM MyTable
WHERE id > :PreviousValue
ORDER BY id ASC
LIMIT 1

For the previous record, use < and DESC .

Simply define an integer id and update it when the user press next or previous and then update the screen based on the updated id.

You can read all records and store them on in a list and when you want to update screen, you can access selected record by calling list.get(id) .

If you don't want to store all records in a list simply select a record from database where its id is equal to id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM