In my app I have activity with tabs (let's say 10 tabs). Each tab page contains Fragment
with ListView
(data displayed in this ListView is loaded dynamically from my server). I use ViewPager
to display these pages. I don't want to keep all the Fragments
in memory, so I decided to use FragmentStatePagerAdapter
(My adapter class extends these class).
Let's say 3rd tab is selected. Then, when I go for example to the first tab,
Fragment
for this tab should be created from scratch (that's fine, it's howFragmentStatePagerAdapter
works) but without restoring previous state of this fragment (e.g.,ListView
shouldn't be scrolled to the position saved when thisFragment
was last accessed - now it is scrolled). So my first question is: how can I achieve such a behaviour? In other words, I want my adapter not to restoreFragment
state, when it is created from scratch.Once again, let's say 3rd tab is selected. Then, when I go for example to the second tab,
Fragment
for this tab should be still in memory (that's fine, it's howFragmentStatePagerAdapter
works), but in this situation I want to decide if myListView
data should be updated (depending on some conditions). How can I notify thisFragment
that it's selected?
PagerAdapter
usingFragmentStatePagerAdapter
code without state saving/restoring parts. It is useful for my second problem too, because now, in my own adapter, I have an easy access to currentFragment
(since there is internalFragments
list - no need to have additional map/array). I was only afraid if my idea was correct, but your answers is exactly the same, so I'm sure now. Thanks a lot. – Quincuncial