Search code examples
androidandroid-cursorloaderandroid-loadermanager

How to pass new data to onCreateLoader


I have an Activity that implements LoaderManager.LoaderCallbacks<Cursor>. The CursorLoader feeds into a RecyclerView (think ListView). So inside onLoadFinished I swap the data inside my adapter.

Imagine the data has to do with stock performance for a day. Now I have a Spinner that allows the user to choose a day. And when the user changes day I want the data to change. So I am thinking that the Loader needs to be able to listen to the parameter. How do I do that? Per the documentation of getSupportLoaderManager().initLoader I am not sure if calling it inside my spinner’s onItemSelected will do that trick. Thanks for any help.


Solution

  • And when the user changes day I want the data to change. So I am thinking that the Loader needs to be able to listen to the parameter

    to me, it sounds like you want to requery your database again when those data change. you can use restartLoader. You have to possibility to provide a different id, which can be used as identifiers for the specific loader. From the documentaion:

    Starts a new or restarts an existing Loader in this manager, registers the callbacks to it, and (if the activity/fragment is currently started) starts loading it.