RecyclerView页脚未显示

时间:2016-07-26 06:37:46

标签: android android-recyclerview footer

我试图在RecyclerView infinte滚动中显示页脚,但是页脚有时显示得那么快,有时根本没有显示。给定代码中是否存在问题?

 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();               

        }
    }

1 个答案:

答案 0 :(得分:1)

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
                        }
                         }
                    }
                }
            });

在我的代码中,在每次加载开始之前,代码集loading = true;中的每个操作集isLoading都为false