Last active
December 30, 2015 00:19
-
-
Save passsy/7748335 to your computer and use it in GitHub Desktop.
LoaderManager.LoaderCallbacks<Cursor> methods with some boilerplate code for a quick CursorLoader start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Loader<Cursor> onCreateLoader(final int id, final Bundle bundle) { | |
// Initialize the CurosorLoader | |
final int code = id - this.hashCode(); | |
switch (code) { | |
case ID1: | |
String selection = null; | |
return new CursorLoader(getActivity(), CONTENT_URI, null, | |
selection, null, null); | |
default: | |
throw new IllegalArgumentException("Loader with id: " + id + " is unknown"); | |
} | |
} | |
@Override | |
public void onLoaderReset(final Loader<Cursor> loader) { | |
// Reset UI | |
switch (loader.getId() - this.hashCode()) { | |
case ID1: | |
break; | |
default: | |
throw new IllegalArgumentException( | |
"Loader with id: " + loader.getId() + " is unknown"); | |
} | |
} | |
@Override | |
public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) { | |
// Update UI | |
if (getActivity() == null) { | |
Log.w(TAG, "you should unregister this loader in onPause ;)"); | |
} | |
switch (loader.getId() - this.hashCode()) { | |
case ID1: | |
break; | |
default: | |
throw new IllegalArgumentException( | |
"Loader with id: " + loader.getId() + " is unknown"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getActivity().getSupportLoaderManager().restartLoader(this.hashCode() + ID1, null, this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
implements LoaderManager.LoaderCallbacks