Skip to content Skip to sidebar Skip to footer

Android: How Do I Return To To Top Of Recyclerview After Adding Item?

I have a RecyclerView list of CardViews. New CardViews are inserted at the top of the list. If the View is currently at the bottom of the CardView list and I click my 'Add' button

Solution 1:

do like this

recyclerview.post(newRunnable() {
        @Overridepublicvoidrun() {
           LinearLayoutManagerlayoutManager= (LinearLayoutManager) mRecyclerView.getLayoutManager();
           layoutManager.scrollToPositionWithOffset(0, 0);
        }
    });

if this does not work check where are you calling this and control executes this statement or not.

Solution 2:

I use this with a "scroll to top" button, you can try work your way around with it :

LinearLayoutManagermlayoutManager= (LinearLayoutManager) rv.getLayoutManager();
    mlayoutManager.scrollToPositionWithOffset(0, 0);

Post a Comment for "Android: How Do I Return To To Top Of Recyclerview After Adding Item?"