Malinskiy / SuperRecyclerView

Pumped up RecyclerView
2.63k stars 470 forks source link

How to disable load more method ? #111

Closed liuzhanta closed 8 years ago

liuzhanta commented 8 years ago

It's has no effect when I invoke hide more ' superRecyclerView.setLoadingMore(false);' .

liuzhanta commented 8 years ago

I think I found the bug . In the SuperRecyclerView you write code like following this:

  private void processOnMore() {
    RecyclerView.LayoutManager layoutManager = mRecycler.getLayoutManager();
    int lastVisibleItemPosition = getLastVisibleItemPosition(layoutManager);
    int visibleItemCount = layoutManager.getChildCount();
    int totalItemCount = layoutManager.getItemCount();  if (((totalItemCount - lastVisibleItemPosition) <= ITEM_LEFT_TO_LOAD_MORE ||
         (totalItemCount - lastVisibleItemPosition) == 0 && totalItemCount > visibleItemCount)
        && !isLoadingMore) {

        isLoadingMore = true;
        if (mOnMoreListener != null) {
            mMoreProgress.setVisibility(View.VISIBLE);
            mOnMoreListener.onMoreAsked(mRecycler.getAdapter().getItemCount(), ITEM_LEFT_TO_LOAD_MORE, lastVisibleItemPosition);
        }
    }
}`

Did you notice the 'isLoadingMore' this field ? It means the recycler view is loading more data . Ok ,then ,you tell us to use the method

 /**
  * Enable/Disable the More event
  */
  public void setLoadingMore(boolean isLoadingMore) {
    this.isLoadingMore = isLoadingMore;
  }

to disable loading more feature, PS : That's the point ! Did you see the problem ? When you setLoadingMore to false, the code

  if (((totalItemCount - lastVisibleItemPosition) <= ITEM_LEFT_TO_LOAD_MORE ||
         (totalItemCount - lastVisibleItemPosition) == 0 && totalItemCount > visibleItemCount)
        && !isLoadingMore) 

still executed. So the solution is :

 private boolean isLoadingMoreEnabled = true;
  public void disableLoadingMore() {
    this.isLoadingMoreEnabled = false;
  }

  public void enableLoadingMore() {
    this.isLoadingMoreEnabled = true;
   }

and add the field into the if (((totalItemCount - lastVisibleItemPosition) <= ITEM_LEFT_TO_LOAD_MORE || (totalItemCount - lastVisibleItemPosition) == 0 && totalItemCount > visibleItemCount) && **isLoadingMoreEnabled**) {

And It works ! :D

NtcWai commented 7 years ago

Thank you, I face the same the problem. Have the lib updated ?