【问题标题】:RecyclerView with load more progressbar at bottomRecyclerView 在底部加载更多进度条
【发布时间】:2016-05-14 18:37:01
【问题描述】:

我尝试实现 addOnScrollListener() 但这个东西每次都从头开始获取数据并加载回收器视图。我想在当前位置之后加载数据。这是我的示例代码

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_load, null);

        progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
        progressBar.setVisibility(View.VISIBLE);

        myClickHandler();

        business_rv = (RecyclerView) view.findViewById(R.id.business_rv);
        business = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL,false);
        business_rv.setHasFixedSize(true);
        business_rv.setLayoutManager(business);
        if (business_rv.getLayoutManager() instanceof LinearLayoutManager) {
            business = (LinearLayoutManager) business_rv.getLayoutManager();
            business_rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    UpdateRecyclerView(url);
                }
            });
        }

        return view;
    }

【问题讨论】:

    标签: android android-recyclerview onscrolllistener


    【解决方案1】:

    您需要的是无尽的回收器视图,它将在滚动时加载数据。在这里,我附上了该实现的链接。

    Follow this link

    【讨论】:

      【解决方案2】:

      把它当作

       _recycler.addOnScrollListener(_recyclerViewOnScrollListener);   
      
       private RecyclerView.OnScrollListener recyclerViewOnScrollListener = new RecyclerView.OnScrollListener() {
                  @Override
                  public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                      super.onScrollStateChanged(recyclerView, newState);
                  }
      
                  @Override
                  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                      super.onScrolled(recyclerView, dx, dy);
                      int visibleItemCount = layoutManager.getChildCount();
                      int totalItemCount = layoutManager.getItemCount();
                      int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
      
                      if (!isLoading && !isLastPage) {
                          if ((visibleItemCount + firstVisibleItemPosition) >= totalItemCount
                                  && firstVisibleItemPosition >= 0
                                  && totalItemCount >= PAGE_SIZE) {
                              loadMoreItems(++currentPage);
                          }
                      }
                  }
          };
      

      【讨论】: