在OnCreateLoader中,有一個id參數,您可以使用它來更改CursorLoader。
你可以做這樣的事情
onCreateLoader(int id, bundle args) {
switch(id) {
case FETCH_CONTACT_ID: {
//Return CursorLoader for fetching contactID
break;
}
case FETCH_CONTACT_INFO: {
//Return CursorLoader for fetching raw contacts
break;
}
}
}
OnLoadFinished(Loader loader, Cursor c) {
switch(loader.getId()) {
case FETCH_CONTACT_ID: {
//Contact IDs have been fetched, so start fetching raw contact data
//Enter the IDs you want to fetch data for in the bundle which will be passed to onCreateLoader()
mLoaderManager().restartLoader(FETCH_CONTACT_INFO, args);
break;
}
case FETCH_CONTACT_INFO: {
//Raw contact info has been fetched, do whatever you want with it
break;
}
}
}
這個線程的問題是你的答案: http://stackoverflow.com/questions/7957418/loadermanager-with-multiple-loaders-how-以獲得正確的光標加載器 –