XRecyclerView的下拉刷新和上拉加载

XRecyclerView  依赖

compile 'com.jcodecraeer:xrecyclerview:1.2.6'

初始化控件

XRecyclerView xRecyclerView = (com.jcodecraeer.xrecyclerview.XRecyclerView) findViewById(R.id.xRecyclerView);

设置点击事件

xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            //刷新
            @Override
            public void onRefresh() {
                data2.clear();
                adapter=null;//把集合和适配器清空 重新请求数据
                page=1;
                initData(page);
                Toast.makeText(MainActivity.this, "刷新成功", Toast.LENGTH_SHORT).show();
                xRecyclerView.refreshComplete();//停止刷新
            }

            @Override
            public void onLoadMore() {
                page++;
                initData(page);
                System.out.println(page);
                Toast.makeText(MainActivity.this, "加载成功", Toast.LENGTH_SHORT).show();
                xRecyclerView.loadMoreComplete();
            }
        });


 
  

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