RecyclerViewの最後の項目の後にスクロールするときに、さらに項目をロードしようとしていますが、何も起こりません。 &最後の項目に移動しましたが、何も起こっていないのに、画面ロード時にはただ1回しかコールしません。&以下はRecyclerViewページネーションが機能しない
私のコードは、スクロール部コード
public abstract class EndlessRecyclerOnScrollListener extends
RecyclerView.OnScrollListener {
public String TAG = EndlessRecyclerOnScrollListener.class
.getSimpleName();
private int previousTotal = 0;
private boolean loading = true;
private int visibleThreshold = 5;
int firstVisibleItem, visibleItemCount, totalItemCount;
private int current_page = 1;
private LinearLayoutManager mLinearLayoutManager;
public EndlessRecyclerOnScrollListener(
LinearLayoutManager linearLayoutManager) {
this.mLinearLayoutManager = linearLayoutManager;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = recyclerView.getChildCount();
totalItemCount = mLinearLayoutManager.getItemCount();
firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
}
}
if (!loading
&& (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
// End has been reached
// Do something
current_page++;
onLoadMore(current_page);
loading = true;
}
}
public abstract void onLoadMore(int current_page);
}
inspectionRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView_Inspections);
final LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
inspectionRecyclerView.setLayoutManager(mLayoutManager);
inspectionRecyclerView.setOnScrollListener(new EndlessRecyclerOnScrollListener(
mLayoutManager) {
@Override
public void onLoadMore(int current_page) {
// do somthing...
Log.v("Call", "Load more");
//api call to load more items goes here
}
});
である私を助けてください。