【发布时间】:2016-07-07 16:24:42
【问题描述】:
好吧,我很抱歉标题没有那么具体和清晰(太努力了),所以我有这个功能
public void fetchData(){
dataQuery.setPageSize(10); // fetch 10 items per request
final boolean[] firstResponse = {true};
final CountDownLatch latch = new CountDownLatch( 1 );
// a callback of fetching data from server
Backendless.Data.of(Note.class).find(dataQuery, new AsyncCallback<BackendlessCollection<Note>>() {
@Override
public void handleResponse(BackendlessCollection<Note> notes) { // here we have the response of request
/// loop for requesting for items until all of them is fetched//////
if(firstResponse[0])
{
firstResponse[0] =false;
}
int size = notes.getCurrentPage().size();
if( size > 0 )
notes.nextPage( this );
else
latch.countDown();
//////////////////////////////////
/// do whatever I want with the fetched data
}
@Override
public void handleFault(BackendlessFault fault) {// here we have the error of request
swipeToReload.setRefreshing(false);
Toast.makeText(getContext(), "" + fault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
所以现在上面的函数在循环中为每个请求获取10 items,并且这个循环一直运行直到检索到所有数据,我想要的是手动运行这个循环(点击按钮我想加载第一个10 个项目,然后我希望它手动工作,而不是再次请求,在按钮单击时获取接下来的 10 个项目)如果有人可以指导我正确的方向,那么它对我很有帮助
【问题讨论】:
标签: java android backendless