MarkoMilos / Paginate

Library for creating simple pagination functionality upon RecyclerView and AbsListView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"onLoadMore" method is passively invoked when the list which uses Paginate initializes

Froyo91 opened this issue · comments

Thanks for your library, it is convenient for me to do pulling-up operations in my app.

However, I found that "onLoadMore" method is passively called in the case where the list which uses Paginate initializes. For example, when the list which is initialized only has two items so that it can not fill the phone screen, the onLoadMore method is invoked strangely. I read your source code, and I found some code in the EndScrollListener.java below:

@Override
    public void onScroll(AbsListView view, int firstVisibleItemPosition, int visibleItemCount, int totalItemCount) {
        if ((totalItemCount - visibleItemCount) <= (firstVisibleItemPosition + visibleThreshold)) {
            callback.onEndReached();
        }

        if (delegate != null) {
            delegate.onScroll(view, firstVisibleItemPosition, visibleItemCount, totalItemCount);
        }
    }

I found that "onEndReached is called" leads to my question. So I change the code above to this:

@Override
    public void onScroll(AbsListView view, int firstVisibleItemPosition, int visibleItemCount, int totalItemCount) {
        if (((totalItemCount - visibleItemCount) <= (firstVisibleItemPosition + visibleThreshold)) && (totalItemCount != visibleItemCount)) {
//        if (((totalItemCount - visibleItemCount) <= (firstVisibleItemPosition + visibleThreshold))) {
            callback.onEndReached();
        }

        if (delegate != null) {
            delegate.onScroll(view, firstVisibleItemPosition, visibleItemCount, totalItemCount);
        }
    }

I use this condition: totalItemCount != visibleItemCount

It seems my queestion has gone out after my change.

Could you please give some advice on my problem and my change on your code? Is my change on your code correct and is there any more efficient solution to solve my question? Please help and sorry for my poor English.If you are puzzled with my question, I will describe my question more detailedly afterwards.

Agree,
this instability on load more is wasting my time for about two days and no clue what to do :(

When onEndReached is called it will call the onLoadMore() method only if you indicate that loading is not currently in progress (by returning false from isLoading()) and that there is more data to load (by returning false from hasLoadedAllItems()). By doing so your are basically saying "I have more pages to load and I'm currently not loading anything" - so the library invokes onLoadMore()

Let me know if I misunderstood you. Also, can you c/p your initialization and callback code?