Skip to content

Instantly share code, notes, and snippets.

@passsy
Last active December 30, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passsy/7748335 to your computer and use it in GitHub Desktop.
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
@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");
}
}
getActivity().getSupportLoaderManager().restartLoader(this.hashCode() + ID1, null, this);
@passsy
Copy link
Author

passsy commented Apr 3, 2014

implements LoaderManager.LoaderCallbacks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment