In app activity I have ViewPager attached to FragmentPagerAdapter which have three items all of them have list views attached to cursor loaders.
public static class TaskListFragment extends Fragment implements LoaderCallbacks<Cursor> {
public TaskListFragment() {
}
protected static final String excludeCompletedArg = "excludeCompleted";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
getLoaderManager().initLoader(filter, cursorArgs, this);
...
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
// TODO Auto-generated method stub
return new CursorLoader(getActivity(),
Uri.parse("content://someurl"),
null,
null,
new String[] { Integer.toString(arg0), arg1.getString(TaskListFragment.excludeCompletedArg) },
null);
}
}
But which way I can force to reload cursor with new bundle argument? For an example I handle onTabReselected of main activity
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
LoaderManager loaderManager = mSectionsPagerAdapter.getItem(tab.getPosition()).getLoaderManager();
}
thows exception.
I don't want to use FragmentStatePagerAdapter instead.
I assume you whant to reload cursor in some situations. In order to do that you may use restartLoader method. In your method onTabReselected you just need to restart loader of given id and pass in the argument to recreate.
It works just like initLoader but always enforces reload. Your onCreateLoader pattern should be:
Refer: http://developer.android.com/reference/android/app/LoaderManager.html http://developer.android.com/guide/components/loaders.html