1

I have ListView inside NestedScrollView (do not want use RecycleListView) in my fragment. List adapter inits in onCreate and not recreated when app back to the fragment from other fragment. But my NestedScrollView then scrolls to the top (can I prevent this?). Without NestedScrollView my ListView stay at the same position.

Konstantin Konopko
  • 5,229
  • 4
  • 36
  • 62

2 Answers2

2

You should retain the list status in onPause() method on the Fragment (save it to the Bundle) and then read and set it in onResume(). Just create some constant key, save then read :-)

The value you will want to save is getScrollY() most probably. Then you will want to restore it with scrollTo(int x, int y) where x=0 and y=savedValue.

Also, you do want to use RecyclerView :-) It is really cool and works really well with NestedScrollView and CoordinatorLayout. Also, it is much easier and quicker to implement than ListView once you get the hang of it. It is also very lightweight. And I had once seen it save a puppy from a fire. RecyclerView is da man! :-D

Kelevandos
  • 7,024
  • 2
  • 29
  • 46
-1

Remove @string/appbar_scrolling_view_behavior form the NestedScrollView layout.

karan vs
  • 3,044
  • 4
  • 19
  • 26