search

Home  >  Q&A  >  body text

Is there any elegant way to handle refreshed/loaded data of the same interface?

I would like to ask you about the request for list data. If you perform pull-down refresh and pull-up loading requests in the same interface, what is a more appropriate way to process the data when obtaining the request result?

My current approach is to pass the data into the same function, and then judge the request in the function. If it is refreshing, clear the data container, and then add the data. If it is not refreshing, add it directly, but it feels like the code is too complex to handle. It doesn’t look good, and you have to do repeated operations every time you process it, and there is no extraction.
Is there any better solution to this situation?

PHP中文网PHP中文网2743 days ago581

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 13:33:18

         /**
         *  请求数据
         * @param page 页码
         * @param status 状态  是刷新 还是加载更多
         */
        private void loadData(int page,int status){
    
            HttpUtil.with(..)
                .url(..)
                .param(..)
                .excute(new Callback(){
    
                void onSuccess(List<bean> result){
                    if(status == REFRESH_STATUS){//刷新状态
                        datas.clear();
                    }
                    datas.addALL(result);
                    adapter.notifyDataSetChanged();
                }
    
            });
    
        }

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-16 13:33:18

    The interface generally requires the page parameter. Page=0 is usually a pull-down refresh

    reply
    0
  • Cancelreply