I want to have two cursor loaders in my application fragment. Each one of them has different set of data and is used in different lists.
I found somewhere that with cursor you can use getId()
method and then using switch do something. But, there is always method: getLoaderManager().initLoader(0,null,this);
after which can be something like this:
adapter = new SimpleCursorAdapter(context, android.R.layout.simple_list_item_1, null, from, to, 0);
This method is only for one cursor, but what if I have adapter1
and adapter2
? How can I determine which cursor is for which adapter?
One possible solution is this. Remove the
LoaderCallbacks
interface from yourFragment
declaration, then create two separate implementations ofLoaderCallbacks
, one for each adapter that you want to set up. Finally in theonLoadFinished
method of each implementation set up the adapters.My solution is to implement callback listeners
....I think you get the idea
Having separate loader callbacks is not necessary. The answer lies in the ID passed to the loader manager:
You can make as many cursor loaders as you like in this way and only implement the callback methods once.