The title may not be accurate so let me describe exactly what I need to do: I have a database of people. I need to display them to user youngest first. Imaging it's an android app with a ListView (or imagine a website, whatever helps). So for the first call I send 50 items to the caller. When the caller scrolls, I want to send another 50; and so on. So my method below accepts the int index
parameter. But I am not sure where to put it. Naturally I want to use startAt
but that method is expecting a cursor. Here is my code below
标题可能不准确,所以让我准确描述一下我需要做什么:我有一个人的数据库。我需要首先向用户显示它们。想象它是一个带有ListView的Android应用程序(或想象一个网站,无论有什么帮助)。因此,对于第一个电话,我向调用者发送了50个项目。当呼叫者滚动时,我想再发送50个;等等。所以我的方法接受int索引参数。但我不知道该把它放在哪里。当然我想使用startAt但该方法需要一个游标。这是我的代码如下
public static Collection<Person> getYoungestKids(int index){
return OfyService.ofy().load().type(Person.class).order("-dob").limit(50).list();
}
1 个解决方案
#1
1
Check out this example to work with Cursors. Using Offsets is considered to be very expensive. You should always use cursors for pagination.
查看此示例以使用游标。使用偏移被认为是非常昂贵的。你应该总是使用游标进行分页。
https://github.com/objectify/objectify/wiki/Queries#cursor-example
https://github.com/objectify/objectify/wiki/Queries#cursor-example
#1
1
Check out this example to work with Cursors. Using Offsets is considered to be very expensive. You should always use cursors for pagination.
查看此示例以使用游标。使用偏移被认为是非常昂贵的。你应该总是使用游标进行分页。
https://github.com/objectify/objectify/wiki/Queries#cursor-example
https://github.com/objectify/objectify/wiki/Queries#cursor-example