I have a ViewPager
with three tabs. In each of the tabs there is a list of movies.
I made it so there is one fragment that contains the ListView
and every time the user chooses a tab, a static reference in the MainActivity
changes, causing the adapter of the list view to refresh with other types of data.
So it's designed like this:
MovieListFragment: a fragment containing a list view and initialising it.
PagerAdapter: the adapter for the view pager. In the getItem
method, it simply returns a new instance of the MovieListFragment
.
MoviesFragment: This is the fragment that holds everything together. It initialises the tabs and the ViewPager and connects them. It also adds a listener for tab select, changing the dataType for the list view accordingly.
By adding logs, I found that the dataType does change correctly.
However, the onCreateView
in the MovieListFragment is not called every time a tab is selected. Thus, the adapter is not refreshing so the list shown is not with the correct dataType.
How do I create the fragment every time a tab is selected, so I can correctly set the dataType for the list view in that specific tab?