SwipeRefreshLayout + RecyclerView 怎么设置下拉刷新过程中禁止再次下拉刷新_安卓软件开发教程-查字典教程网
SwipeRefreshLayout + RecyclerView 怎么设置下拉刷新过程中禁止再次下拉刷新
SwipeRefreshLayout + RecyclerView 怎么设置下拉刷新过程中禁止再次下拉刷新
发布时间:2018-02-01 来源:查字典编辑
摘要:RT,刷新过程中再次触发下拉刷新的时候,往上滑动会将两次刷新的数据一起加载出来,想要避免这种情况该怎么做附代码:recyclerView.s...

RT,刷新过程中再次触发下拉刷新的时候,往上滑动会将两次刷新的数据一起加载出来,想要避免这种情况该怎么做

附代码:

recyclerView.setHasFixedSize(true);

        recyclerView.setAdapter(adapter);

        recyclerView.setLayoutManager(manager);

        swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);

        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override

            public void onRefresh() {

                page = 1;

                list.clear();

                adapter.notifyDataSetChanged();

                presenter.testRank(libid, userid, interval, "10", String.valueOf(page));

                isLastPage = false;

                isLimit = false;

                swipeRefreshLayout.setRefreshing(false);

            }

        });

        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

                                         //用来标记是否正在向最后一个滑动,既是否向右滑动或向下滑动

                                         @Override

                                         public void onScrollStateChanged(RecyclerView recyclerView, int newState) {

                                             LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();

                                             // 当不滚动时

                                             if (newState == RecyclerView.SCROLL_STATE_IDLE) {

                                                 //获取最后一个完全显示的ItemPosition

                                                 int lastVisibleItem = manager.findLastCompletelyVisibleItemPosition();

                                                 int totalItemCount = manager.getItemCount();

                                                 // 判断是否滚动到底部,并且是向右滚动

                                                 if (lastVisibleItem == (totalItemCount - 1) && isSlidingToLast) {

                                                     //加载更多功能的代码

                                                     isMore = true;

                                                     if (isFirst) {

                                                             page++;

                                                         if (page < = maxPage) {

                                                             presenter.testRank(libid, userid, interval, "10", String.valueOf(page));

                                                         }

                                                         if (!isLastPage && !isLimit && page == maxPage + 2) {

                                                             DeviceUtil.MyToast(RankActivity.this, "排名只显示前" + maxPage * 10 + "名");

                                                             isLimit = true;

                                                             isLastPage = true;

                                                         } else {

                                                         if (!isLastPage) {

                                                             page++;

                                                             presenter.testRank(libid, userid, interval, "10", String.valueOf(page));

                                                         }

                                                     }

                                                 }

                                             }

                                         }

                                         @Override

                                         public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

                                             super.onScrolled(recyclerView, dx, dy);

                                             //dx用来判断横向滑动方向,dy用来判断纵向滑动方向

                                             if (dy  > 0) {

                                                 //大于0表示,正在向右滚动

                                                 isSlidingToLast = true;

                                             } else {

                                                 //小于等于0 表示停止或向左滚动

                                                 isSlidingToLast = false;

                                             }

                                         }

                                     }

        );

    }

回复讨论(解决方案)

大神们呢 SwipeRefreshLayout 可以判断是否在刷新中, swipeRefresh.isRefreshing() , 如果在刷新中,你可以不去做请求操作。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新安卓软件开发学习
    热门安卓软件开发学习
    编程开发子分类