【发布时间】: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;
}
}
});
【问题讨论】:
-
使用 SwipeRefreshLayout
标签: java android android-recyclerview