MarkoMilos / Paginate

Library for creating simple pagination functionality upon RecyclerView and AbsListView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OnLoadMore calls 2 times for the first time

abumoallim opened this issue · comments

Same problem here!
and also if you try to scroll fast (up and down) and get near to end of the list, you may get stuck into infinite load more!

Anyone know to fix this? I have same problem?

How many items are loaded on first call and what is your threshold set to? If your threshold is set to 3 and you only load 2 items on first batch, it will likely trigger again because it thinks the user is nearing the bottom of the list.

Same problem here!
and also if you try to scroll fast (up and down) and get near to end of the list, you may get stuck into infinite load more!
Same issue . Do you find the solution?

The problem is that the library calls checkEndOffset() twice: first, upon initialization (makes sense) and, second, when the RecyclerView's onScrolled() event takes place. Note that onScrolled() is being called with dx and dy equal to 0. This is due to RecyclerView calling the scroll listener when layout changes happen, even if no scroll was performed by the user.

I don't know if the bug is with this library or with RecyclerView calling the scroll event when it shouldn't (from my point of view, it's a really stupid design decision from the Android team).

So far, my solution has been to immediately set a member isLoading flag to true. This is the flag that the Paginate callback is returning.

@necavit could you please explain a little bit more how to solve this? Where do you set the isLoadingFlag?

@necavit could you please explain in which method you set the isLoading flag to true immediately?

The truth is that onLoadMore() is called once on initialization and each time when RecyclerView.OnScrollListener calls onScrolled(...).

However, before onLoadMore() is called the check is performed to assert that loading is not currently in progress by calling Paginate.Callbacks isLoading() method.

If you return true here, even tough check is performed onLoadMore() won't be called. That said, the first time when onLoadMore() is called you need to set your flag (or however you are handling this) to true immediately in the main thread.

I'm closing this issue for now, please fill free to reopen it with a code example demonstrating the issue.