简体   繁体   中英

How to know that last recyclerView item of first or current screen/page is loaded, any Callbacks but gets called once?

I am using a grid layout of recyclerView and have tried several options using either onLayoutCompled methods and also by onScollListner methods, tried this answer but it's stiil calling multiple times as each item keeps loading, nothing is working.

Just want to detect the last recyclerView item of the particular screen is completely loaded or visible to the user according to their screen size Or we can say that when the user's current screen is full of the recyclerView Items, any way to detect that? ANd should be called only once . Any help would be great.
Thank you for your valuable time.

You can use a Sharedpref value which can be set to true in your onScrollStateChanged method based on your condition.

@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
   super.onScrollStateChanged(recyclerView, newState);

   if (newState != RecyclerView.SCROLL_STATE_IDLE) {
      return;
   }

   boolean isLastPositionVisible = mFollowingLayoutManager.findLastVisibleItemPosition() == getList().size() - 1

   if(isLastPositionVisible && getSharedPrefValue()) {
      // Call your method
      // Set sharedpref value to true.
   }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM