I have a FragmentActivity with a ViewPager in it - this ViewPager contains three ListViews - each of them has its own unique adapters (and unique data sets).
I would like to use AsyncTaskLoader to populate these adapters, but ONLY when the selected view is selected in the ViewPager.
Do I need to initialize the bootloader in the onCreate method? (below code)
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_foo); getSupportLoaderManager().initLoader(0, null, this); getSupportLoaderManager().initLoader(1, null, this); getSupportLoaderManager().initLoader(2, null, this); }
Or can you normally call the initLoader (...) call interactively, for example, the listening result for OnPageChangeListener.onPageSelected?
mPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int newPage) { getSupportLoaderManager().initLoader(newPage, null, this); } ... }
I want to avoid the need to run potentially 3 temporary bootloaders in front if the user can only look at the first view in the pager.
EDIT:. Or would it be better if the ViewPager used a fragment for each view, and each fragment would be responsible for managing its own loader?
Npike source share