循环滚动Recyclerview重新加载页面onscroll

时间:2015-08-27 09:38:39

标签: android infinite-scroll android-recyclerview

我试图在Android中实现Endless Recyclerview并能够加载下一组数据在RecyclerView的滚动上。

但是一旦我收到新的数据集,我的回收活动就会重新加载,而且项目会从初始数据中显示出来。我甚至试过EndlessScrollRecyclListener,但它是一样的。

以下是我尝试的代码

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

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

        visibleItemCount = mRecyclerView.getChildCount();
        totalItemCount = mLayoutManager.getItemCount();
        firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();

        if (loading) {
            if (totalItemCount > previousTotal) {
                loading = false;
                previousTotal = totalItemCount;
            }
        }
        if (!loading && (totalItemCount - visibleItemCount) 
            <= (firstVisibleItem + visibleThreshold)) {
            // End has been reached

           new LoadData().execute(0);

            loading = true;
        }
    }
}); 

0 个答案:

没有答案