I have a NestedScrollView in which there is a TextView with a large amount of text, I need to save the scroll event when I stop it in SharedPreferences , is it possible to do this without creating a separate class, if not, how to do it in a separate class, and how to do it better ?

    1 answer 1

    I managed to do this:

    Implemented setOnScrollChangeListener :

     mainNestedScroll.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { mEditor.putInt("ScrollX", scrollX); mEditor.putInt("ScrollY", scrollY); mEditor.apply(); } }); 

    And in the onResume method:

     final int scrollX = mPreferences.getInt("ScrollX", 0); final int scrollY = mPreferences.getInt("ScrollY", 0); mainNestedScroll.post(new Runnable() { @Override public void run() { mainNestedScroll.scrollTo(scrollX, scrollY); } });