我正在使用Android Architecture组件中的PageKeyedDataSource添加分页。它可以运行,但是确切的页面会不断重复。
I was following this post and tried in same way. But it repeats in my case
我试图记录params.key,以便我可以弄清楚重复发生的确切位置并得到以下结果:
D / ScheduleDataSource:关键11和总计项:12
随着我不断滚动,然后添加密钥直到它达到12,即12/12完成,突然我得到了空指针异常
public class ScheduleDataSource extends PageKeyedDataSource<Long,GeneralMatchItem> {
public void loadInitial (@NonNull LoadInitialParams<Long> params, @NonNull LoadInitialCallback<Long, GeneralMatchItem> callback){
total_items = response_obj.getInt("total_items"); // This is the total items received fromthe response
....
....
callback.onResult(internationalScheduledMatchItemsList,null, 2L);
}
public void loadAfter(@NonNull LoadParams<Long> params, @NonNull LoadCallback<Long, GeneralMatchItem> callback) {
....
long nextKey = (params.key == total_items)? null : params.key+1; // This throws null pointer when the pages are 12/12
callback.onResult(tempList,nextKey);
}
...
}
我希望recyclerview不要一次又一次地重复加载过程