XrecycleView上拉加载下拉刷新

//依赖

implementation 'com.jcodecraeer:xrecyclerview:1.3.2'

//glrade中加入

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '27.1.1'
            }
        }
    }
}

//activity

   private XRecyclerView xrecy;
    int  page=1;
    int count=8;
    private ShopAdapter adapter;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View inflate = inflater.inflate(R.layout.fragment_cir, container, false);
        xrecy = inflate.findViewById(R.id.xrecyview);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        xrecy.setLayoutManager(linearLayoutManager);
        final ViewPresenter viewPresenter = new IViewPresenter(this);
        viewPresenter.getModeldata(page,count);
        xrecy.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        page=1;
                        count=8;
                        viewPresenter.getModeldata(page,count);
                        adapter.notifyDataSetChanged();
                        xrecy.refreshComplete();
                    }
                }, 2000);
            }

            @Override
            public void onLoadMore() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
//                        page++;
                        count++;
                        viewPresenter.getModeldata(page,count);
                        adapter.notifyDataSetChanged();
                        xrecy.loadMoreComplete();
                    }
                }, 3000);
            }
        });
        return inflate;
    }

 

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