手动控制自动功能

时间:2016-07-07 16:24:43

标签: java android backendless

我为没有那么具体和清晰的标题而道歉(为此尝试太难),所以我有这个功能

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个项目)如果任何人可以指导我正确的方向然后它会对我有帮助

1 个答案:

答案 0 :(得分:1)

删除倒计时锁定并更改签名,如下所示:

public void fetchData( int offset )

在实现中,保持代码设置页面大小,但也添加:

dataQuery.setOffset( offset );

这将从指定的偏移量中获取下一页数据。无需在响应者中调用nextPage。您得到的结果将是指定偏移量的“pageSize”记录块。