上拉加载下拉刷新

public class Activity_YYGL_YiYuYue extends Activity_Base implements SwipeRefreshLayout.OnRefreshListener, BaseQuickAdapter.RequestLoadMoreListener{

    private RecyclerView mRecyclerView;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private YiYuYueAdapter mAdapter;
 
    private int index = 1 ;
    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_yygl_yiyuyue);
    }

    @Override
    protected void findViewById() {
        mRecyclerView = findViewById(R.id.recyclerView_daiyuyue);
        mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
        mSwipeRefreshLayout.setOnRefreshListener(this);

    }


    @Override
    protected void processLogic() {
        mAdapter = new YiYuYueAdapter(R.layout.item_yygl_yiyuyue, yiYuYueBeans);
        mAdapter.setOnLoadMoreListener(this,mRecyclerView);
        mAdapter.disableLoadMoreIfNotFullPage();
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerView.setAdapter(mAdapter);
        getData();
    }

    private void getData() {
        HashMap map = new HashMap<>();
        map.put(MyConstant.TOKEN, Token_Test.TOKEN_DEBUG);
 
        map.put("page",index+"");
        map.put("rows",10+"");
        new OkUtils().post(MyURL.YIYUYUE,map).setOnLoadDataListener(new OkUtils.OnLoadDataListener() {
            @Override
            public void onSuccess(ArrayList jsonList) {

                if(index == 1){
                    mAdapter.setNewData(list);
                }else{
                    mAdapter.addData(list);
                }

                if(list == null || list.size() == 0 || list.size() < 10){
                    mAdapter.loadMoreEnd();
                }else{
                    mAdapter.loadMoreComplete();
                }
                mSwipeRefreshLayout.setRefreshing(false);
            }

            @Override
            public void loadError(String errorMsg) {
                mSwipeRefreshLayout.setRefreshing(false);
                mAdapter.loadMoreFail();


            }
        }).execute4List();
    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public void onRefresh() {
       index = 1;
       mAdapter.setEnableLoadMore(false);
       getData();
    }

    @Override
    public void onLoadMoreRequested() {
        ++index;
        getData();
    }
}

你可能感兴趣的:(上拉加载下拉刷新)