发表文章

[最新] SmartRefreshLayout OkHttpUtils加载刷新

qq34736014 24天前 0

版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/qq_34736014/article/details/82180083

刷新的方法

public void getRefreshProductList(){

        JSONObject info = new JSONObject();
        int uid = SoftApplication.softApplication.getUserInfo().uid;

        info.put("pageSize",page+"");//第一:page不变
        info.put("firstResult",0+"");//第二:刷新的时候直接写0


        OkHttpUtils.get()
                .url(Constants.server_address+ "index/singleProductList139.do")
                .addParams("auth",SoftApplication.softApplication.getAuthJsonObject(info.toString()))
                .addParams("info",info.toString())
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        
                        //mSrl.finishRefresh(0);
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        
                        firstResult=1;//第三:刷新完以后让firstResult=1
                        mSrl.finishRefresh(0);

                        SingleProduceBean singleProduceBean = JSONObject.parseObject(response, SingleProduceBean.class);
                        List<SingleProduceBean.ResultdataBean.ListBean> list =
                                singleProduceBean.getResultdata().getList();

                        //第四:
                        if(list.size()==0){
                            hasMorePages=false;
                        }else{
                            hasMorePages=true;
                        }

                        mAdapter.setNewData(list);
                        mAdapter.loadMoreComplete();

                    }
                });
    }

加载的方法:

public void getProductList(){
        JSONObject info = new JSONObject();
        info.put("pageSize",page+"");//
        info.put("firstResult",firstResult+"");//第一:firstResult

        OkHttpUtils.get()
                .url(Constants.server_address+ "index/singleProductList139.do")
                .addParams("auth",SoftApplication.softApplication.getAuthJsonObject(info.toString()))
                .addParams("info",info.toString())
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("SingleProductActivity", " onError: "+e.toString() );
                        //mSrl.finishRefresh(0);
                    }

                    @Override
                    public void onResponse(String response, int id) {
                       
                        //第二:
                        firstResult++;
                        mSrl.finishRefresh(0);

                        SingleProduceBean singleProduceBean = JSONObject.parseObject(response, SingleProduceBean.class);
                        List<SingleProduceBean.ResultdataBean.ListBean> list =
                                singleProduceBean.getResultdata().getList();

                         //第三:
                        if(list.size()==0){
                            hasMorePages=false;
                        }else{
                            hasMorePages=true;
                        }
                        mAdapter.addData(list);
                        mAdapter.loadMoreComplete();
                    }
                });
    }

加载的时候:

    @Override
    public void onLoadMoreRequested() {

        if(hasMorePages){
            getProductList();
        }else{
            mAdapter.loadMoreEnd(false);
        }

    }

 

相关推荐
最新评论 (0)
返回
发表文章
qq34736014
文章数
28
评论数
0
注册排名
737316