Byron
Byron

Reputation: 3913

How to Implement multiple loaders in ListFragment

I currently have a list fragment that loads a list of contacts from the ContactsContract.Data.CONTENT_URI using the LoaderManager.LoaderCallbacks. I also have a sqlite table that has contacts that have been added manually into my app by the user, I am using a ContentProvider for my other table.

I would like to load both the sqlite table as well as the ContactsContract.Data.CONTENT_URI using LoaderManager callbacks but I have not been able to find any examples as to how this can be done.

Is this even possible, can some one point me to an example of how to implement this behavior?

Upvotes: 0

Views: 352

Answers (1)

tyczj
tyczj

Reputation: 73753

you supply a different id for each loader you want so that you can decipher between what loader is called

getLoaderManager().initLoader(0,null,this);
getLoaderManager().initLoader(1,null,this);

then in your onLoadFinished just get the if of the loader that was called

public void onLoadFinished(Loader<Cursor> loader, Cursor arg1) {
    loader.getId()
    ....
}

Upvotes: 1

Related Questions