android - How to randomly populate a fragment with database data -


i have fragment displays data gotten database(sqlite) row. want achieve pic different row database , populate fragment on button click. if possible, row picked randomly. hope asked question right. in advance

one possible way query rows @ once random order , keep cursor around. every time button clicked, advance cursor position , use data. when run out of rows, can query again randomized cursor , repeat.

i'm not sure query code looks like, want essentially

select [columns] [table] order random(); 

the important part order random().

note strategy not allow same row data appear second time unless exhaust entire cursor once. if that's not acceptable, next possibility query every time button clicked , this:

select [columns] [table] _id != [current_item_id] order random() limit 1; 

whatever primary key column (my example uses _id), make query exclude row value same current item. order random() again , limit 1 return 1 row.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -