Skip to main content

what i did to restore the scroll position after refreshing the RecyclerView on button clicked:

`if (linearLayoutManager != null) {

if (linearLayoutManager != null) {  index = linearLayoutManager.findFirstVisibleItemPosition();   View v = linearLayoutManager.getChildAt(0);   top = (v == null) ? 0 : (v.getTop() - linearLayoutManager.getPaddingTop());   Log.d("TAG", "visible position " + " " + index);  }  else{   index = 0;  }  linearLayoutManager = new LinearLayoutManager(getApplicationContext());  linearLayoutManager.scrollToPositionWithOffset(index, top);`; 

getting the offset of the first visible item from the top before creating the linearLayoutManager object and after instantiating it the scrollToPositionWithOffset of the LinearLayoutManager object was called.

what i did to restore the scroll position after refreshing the RecyclerView on button clicked:

`if (linearLayoutManager != null) {

 index = linearLayoutManager.findFirstVisibleItemPosition();   View v = linearLayoutManager.getChildAt(0);   top = (v == null) ? 0 : (v.getTop() - linearLayoutManager.getPaddingTop());   Log.d("TAG", "visible position " + " " + index);  }  else{   index = 0;  }  linearLayoutManager = new LinearLayoutManager(getApplicationContext());  linearLayoutManager.scrollToPositionWithOffset(index, top);` 

getting the offset of the first visible item from the top before creating the linearLayoutManager object and after instantiating it the scrollToPositionWithOffset of the LinearLayoutManager object was called.

what i did to restore the scroll position after refreshing the RecyclerView on button clicked:

if (linearLayoutManager != null) {  index = linearLayoutManager.findFirstVisibleItemPosition(); View v = linearLayoutManager.getChildAt(0); top = (v == null) ? 0 : (v.getTop() - linearLayoutManager.getPaddingTop()); Log.d("TAG", "visible position " + " " + index); } else{ index = 0; } linearLayoutManager = new LinearLayoutManager(getApplicationContext()); linearLayoutManager.scrollToPositionWithOffset(index, top); 

getting the offset of the first visible item from the top before creating the linearLayoutManager object and after instantiating it the scrollToPositionWithOffset of the LinearLayoutManager object was called.

Source Link
tsiro
  • 2.4k
  • 3
  • 28
  • 49

what i did to restore the scroll position after refreshing the RecyclerView on button clicked:

`if (linearLayoutManager != null) {

 index = linearLayoutManager.findFirstVisibleItemPosition(); View v = linearLayoutManager.getChildAt(0); top = (v == null) ? 0 : (v.getTop() - linearLayoutManager.getPaddingTop()); Log.d("TAG", "visible position " + " " + index); } else{ index = 0; } linearLayoutManager = new LinearLayoutManager(getApplicationContext()); linearLayoutManager.scrollToPositionWithOffset(index, top);` 

getting the offset of the first visible item from the top before creating the linearLayoutManager object and after instantiating it the scrollToPositionWithOffset of the LinearLayoutManager object was called.