私はloadmoreでSuperslim Libraryを使用していますが、エラーが発生します。さらに負荷のためにEndlessRecyclerOnScrollListenerクラスを1つ作成しますが、それは動作しません。より多くのrecyclerviewをsuperslimライブラリでロードする
私はこれを以下の方法で呼び出しています。
mViews.mRecyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(new LayoutManager(getActivity())) {
@Override
public void onLoadMore(int current_page) {
if (skipItem == 0)
skipItem = 1 * current_page;
else
skipItem = skipItem * current_page;
new ServiceSync().execute("26", String.valueOf(skipItem));
}
});
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 4; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;
private int current_page = 1;
private LayoutManager mlayoutManager;
public EndlessRecyclerOnScrollListener(LayoutManager linearLayoutManager) {
this.mlayoutManager =(LayoutManager) linearLayoutManager;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = recyclerView.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
// Do something here
current_page++;
loading = true;
}
}
public abstract void onLoadMore(int current_page);
}
エラーログ:
java.lang.NullPointerException at com.tonicartos.superslim.SectionData.<init>(SectionData.java:36)
at com.tonicartos.superslim.LayoutManager.findFirstVisibleItem(LayoutManager.java:156)
at com.tonicartos.superslim.LayoutManager.findFirstVisibleItemPosition(LayoutManager.java:187)
at fourever.textile.notificationadapter.notifications$EndlessRecyclerOnScrollListener.onScrolled(notifications.java:235)
at android.support.v7.widget.RecyclerView.dispatchOnScrolled(RecyclerView.java:3704)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2947)
申し訳ありませんが、同じエラーが発生していません –