Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • RecycleView misbehaving! "notifyItemRangeInserted(int positionStart, int itemCount)" method taking too long to add item views

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 2.86k
    Answer it

    RecyclerView is not behaving properly when added as child of a NestedScollView (New Items added to RecyclerView taking more than 2 mins to reflect)

     

    RecyclerView is not behaving properly when added as child of a NestedScollView

    PROBLEM -  notifyItemRangeInserted(int positionStart, int itemCount) method of RecyclerView is taking more than 2 mins to add the new Items views to the window.

     

    a. When the positionStart = 0, it is adding the the items instantly, but as all the items are getting rebind to the adapter again, images are also reloaded again. So this is not the best practice to use positionStart = 0.

     

    b. When the positionStart = currentSize + 1, it is taking more than 2 mins to add the newly added items.

     

    EXPECTED BEHAVIOR - It should add the views within fraction of seconds. 

     

    NOTE - Probably this is happening, because the RecyclerView added inside a NestedScrollView. Please look into this issue as it is restricting the developers to use this component while using NestedScrollView as its parent view to achieve the UI design. 

     

    CODE  SNIPPET : 

     

    ===================================================================

     if (productList != null && productList.getData().size() > 0) {
    
                    int currentSize = adapter.getItemCount(); // Getting current items Count
    
                    adapter.addToProductsList(productList);  // Adding new items to the existing list
    
                    adapter.notifyItemRangeChanged(currentSize+1, adapter.getItemCount());

    ===================================================================

 2 Answer(s)

  • @Amit I have already post the code snippet. This call is happening in Main Thread itself. Finally I got the answer. This is because I have set hasFixedSize(true) to the recycler view. After making it hasFixedSize(false) it worked.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: