【问题标题】:control an Automated function manually手动控制自动化功能
【发布时间】: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


    【解决方案1】:

    移除倒计时锁并更改签名如下:

    public void fetchData( int offset )
    

    在实现中,保留设置页面大小的代码,还要加上这个:

    dataQuery.setOffset( offset );
    

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

    【讨论】:

    • 非常感谢您的回复,您能解释一下这个dataQuery.setOffset( offset )吗?
    • 从服务器加载的所有对象都是按顺序组织的。第一个对象的偏移量为 0,第二个对象的偏移量为 1,依此类推。当您使用 dataQuery.setOffset 设置偏移量时,您指示服务器从指定的偏移量加载下一“页”对象。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多