arps
arps

Reputation: 417

RecyclerView footer is not showing

I have tried to show footer in RecyclerView infinte scrolling but the footer is sometimes shown so fast sometimes it doesnt show at all.Is there problem in the given code??

 public class CustomRecyclerViewScrollListener extends    RecyclerView.OnScrollListener {
    int visibleCount = 0;
    int totalItemCount = 0;
    int pastVisibleItems = 0;
    int lastVisibleItem=0;

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);

        visibleCount = llm.getChildCount();
        totalItemCount = llm.getItemCount();
        pastVisibleItems = llm.findFirstVisibleItemPosition();
        lastVisibleItem=llm.findLastVisibleItemPosition();
        if (!isLoading && !dataFinished && list.size() % 10 == 0) {
            if ((visibleCount + pastVisibleItems) >= totalItemCount) {
                    isLoading = true;
                    loadMore();
                    adapter.showViewHolderFooter();                   

                 }
            }
        } else {             
               adapter.hideViewHolderFooter();               

        }
    }

Upvotes: 1

Views: 250

Answers (1)

Ucdemir
Ucdemir

Reputation: 3098

private int firstVisibleItem, visibleItemCount,totalItemCount,pastVisiblesItems;
private boolean loading = true;

    reyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    if (dy > 0) //check for scroll down
                    {
                        visibleItemCount = mLayoutManager.getChildCount();
                        totalItemCount = mLayoutManager.getItemCount();
                        pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();

                        if (loading) {
                            if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                                loading = false;
                                expandapleInt++;

                              //Your operation
                        }
                         }
                    }
                }
            });

In my code for every operation set loading = true; in your code set isLoading to false before every load starts

Upvotes: 1

Related Questions