【问题标题】:RecyclerView endless scroll to top (chat app)RecyclerView 无限滚动到顶部(聊天应用)
【发布时间】:2018-08-19 19:53:34
【问题描述】:

我目前正在使用THIS TECHNIQUE 使我的 RecyclerView 无休止;但问题是我想要它完全相反。当用户像聊天信使一样向上滚动时,我想将数据加载到适配器中。

private int previousTotal = 0;
private boolean loading = true;
private int visibleThreshold = 5;
int firstVisibleItem, visibleItemCount, totalItemCount;

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

            Log.i("Yaeye!", "end called");

            // Add to data set
            chatMessages.add(0, new Message("Hello World!"));

            loading = true;
        }
    }
});

【问题讨论】:

标签: java android android-recyclerview


【解决方案1】:

【讨论】:

猜你喜欢
  • 2017-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-10
相关资源
最近更新 更多