public void onScrolled ( ) { // due to a bug in 21: https://code.google.com/p/android/issues/detail?id=162753, which cause getDecoratedStart() throws NullPointException // officially reported it has been fixed in v22 final int lastPosition = getLayoutManager ( ) . findLastVisibleItemPosition ( ) ; final int firstPosition = getLayoutManager ( ) . findFirstVisibleItemPosition ( ) ; int lastCardIndex = - 1 ; int firstCardIndex = - 1 ; int position = lastPosition ; //find the last visible item in card for ( int i = lastPosition ; i >= firstPosition ; i -- ) { lastCardIndex = mGroupBasicAdapter . findCardIdxFor ( i ) ; if ( lastCardIndex >= 0 ) { position = i ; break ; } } for ( int i = firstCardIndex ; i <= lastPosition ; i ++ ) { firstCardIndex = mGroupBasicAdapter . findCardIdxFor ( i ) ; if ( firstCardIndex >= 0 ) { break ; } } if ( lastCardIndex < 0 || firstCardIndex < 0 ) return ; final CardLoadSupport loadSupport = getService ( CardLoadSupport . class ) ; if ( loadSupport == null ) return ; List < Card > cards = mGroupBasicAdapter . getGroups ( ) ; //check the loadmore state of current card first range is inclusive-exclusive Card current = cards . get ( lastCardIndex ) ; Pair < Range < Integer > , Card > pair = mGroupBasicAdapter . getCardRange ( lastCardIndex ) ; if ( pair != null && position >= pair . first . getUpper ( ) - mPreLoadNumber ) { // async load if ( ! TextUtils . isEmpty ( current . load ) && current . loaded ) { // page load if ( current . loadMore ) { loadSupport . loadMore ( current ) ; loadSupport . reactiveDoLoadMore ( current ) ; } return ; } } boolean loadedMore = false ; for ( int i = firstCardIndex ; i < Math . min ( lastCardIndex + mPreLoadNumber , cards . size ( ) ) ; i ++ ) { Card c = cards . get ( i ) ; // async load if ( ! TextUtils . isEmpty ( c . load ) && ! c . loaded ) { // page load if ( c . loadMore && ! loadedMore ) { // only load one load more card loadSupport . loadMore ( c ) ; loadSupport . reactiveDoLoadMore ( c ) ; loadedMore = true ; } else { loadSupport . doLoad ( c ) ; loadSupport . reactiveDoLoad ( c ) ; } c . loaded = true ; } } if ( mEnableAutoLoadMore && mGroupBasicAdapter . getItemCount ( ) - position < mPreLoadNumber ) { loadMoreCard ( ) ; } }
Call this method in RecyclerView s scroll listener . Would trigger the preload of card s data .