如何使用 limit 和 offset 来分页数据
我是 SQLite 新手,我不知道如何使用 limit 和 offset 从数据库中选择有限数量的数据,我的意思是我知道查询短语,但如何在游标中使用它以便我可以获得这些数据进入列表视图?
目前我正在使用下面的代码从数据库中查询数据并在列表视图中显示它们,但似乎我为一个查询查询了太多数据并且 SQLite 无法增长,所以我想将查询拆分为一些较小的查询并执行有一段时间,有人建议我尝试限制和抵消,但我用谷歌搜索了一下,互联网上确实没有太多关于它的信息。
有人可以向我提供这方面的指南吗?一个例子或教程,任何都可以,谢谢
channellist = (ListView) findViewById(R.id.Channel);
mDB = new ChannelDB(this);
String[] columns = {mDB.KEY_ID, mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_PATH, mDB.KEY_DBLINK};
String table = mDB.channelS_TABLE;
c = mDB.getHandle().query(table, columns, null, null, null, null, null);
startManagingCursor(c);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.channelview,
c,
new String[] {mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_DBLINK},
new int[] {R.id.poster, R.id.channel, R.id.douban});
adapter.setViewBinder(new ChannelViewBinder(this));
channellist.setAdapter(adapter);
I am new to SQLite and I don't know how to use limit and offset to select a limit number of data from the database, I mean I know the query phrase, but how to use it in a cursor so I can get those data into a listview?
Currently I am using the code below to query data from the database and show them in a listview but it seems I query too much data for one query and the SQLite fail to grow, so I want to split the query into some smaller ones and do it in one time,someone suggested me to try limit and offset,but I googled it there are really not much about it on the Internet.
Would somebody kindly provide me the guide to this? an example or a tutoral, anything will do,thx
channellist = (ListView) findViewById(R.id.Channel);
mDB = new ChannelDB(this);
String[] columns = {mDB.KEY_ID, mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_PATH, mDB.KEY_DBLINK};
String table = mDB.channelS_TABLE;
c = mDB.getHandle().query(table, columns, null, null, null, null, null);
startManagingCursor(c);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.channelview,
c,
new String[] {mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_DBLINK},
new int[] {R.id.poster, R.id.channel, R.id.douban});
adapter.setViewBinder(new ChannelViewBinder(this));
channellist.setAdapter(adapter);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将最后一个参数传递为数字作为字符串,就像您需要获取 10 一样,那么您可以这样做
以获取更多参考,请参阅 如何使用 LIMIT 参数在 Android 的 SQLite 查询中
pass the last argument with number as string like you need fetch 10 then you can do like this way
for more reference see How to use the LIMIT argument in an SQLite Query with Android