【发布时间】:2017-01-20 17:24:02
【问题描述】:
我在我的应用程序中使用 RecyclerView 和 CardView,当用户滑动到 RecyclerView 的最末端时,我尝试进行分页操作,然后在用户向上滑动时加载更多内容。 (就像向下滑动刷新)。我现在拥有的是当用户到达 RecyclerView 的最后一项时,它将自动加载。如何更改它以便在用户拉起时加载?
private RecyclerView.OnScrollListener recyclerViewOnScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView,
int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(dy > 0) //check for scroll down
{
visibleItemCount = gmLayoutManager.getChildCount();
totalItemCount = gmLayoutManager.getItemCount();
pastVisiblesItems = gmLayoutManager.findFirstVisibleItemPosition();
int loadedItems = pastVisiblesItems + visibleItemCount;
//System.out.println(visibleItemCount + "/n" +totalItemCount + "/n"+pastVisiblesItems + "/n" + loadedItems);
if (true)
{
if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount)
{
loading = false;
Log.v("...", "Last Item !");
//Do pagination.. i.e. fetch new data
String api = "stores?offset=10";
getData(api); //Load more data
}
}
}
}
};
【问题讨论】:
标签: android pagination