Android CursorLoader - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android CursorLoader class.

This code example shows how to use the following methods:setProjection, setSelection, setSortOrder, setUri
        mUnknownNameText = context.getText(android.R.string.unknownName);
    } 
 
    @Override 
    public void configureLoader(CursorLoader loader, long directoryId) {
        loader.setUri(ContactMethods.CONTENT_URI);
        loader.setProjection(POSTALS_PROJECTION);
        loader.setSortOrder(People.DISPLAY_NAME);
        loader.setSelection(ContactMethods.KIND + "=" + android.provider.Contacts.KIND_POSTAL);
    } 
 
    @Override 
    public String getContactDisplayName(int position) {
        return ((Cursor)getItem(position)).getString(POSTAL_DISPLAY_NAME_COLUMN_INDEX);
    } 
 
    public Uri getContactMethodUri(int position) {
        Cursor cursor = ((Cursor)getItem(position));
        long id = cursor.getLong(POSTAL_ID_COLUMN_INDEX);
        return ContentUris.withAppendedId(ContactMethods.CONTENT_URI, id);
8
CodeRank
This code example shows how to use the following methods:setProjection, setSortOrder, setUri
        mUnknownNameText = context.getText(android.R.string.unknownName);
    } 
 
    @Override 
    public void configureLoader(CursorLoader loader, long directoryId) {
        loader.setUri(Phones.CONTENT_URI);
        loader.setProjection(PHONES_PROJECTION);
        loader.setSortOrder(Phones.DISPLAY_NAME);
    } 
 
    @Override 
    public String getContactDisplayName(int position) {
        return ((Cursor)getItem(position)).getString(PHONE_DISPLAY_NAME_COLUMN_INDEX);
    } 
 
    public Uri getPhoneUri(int position) {
        Cursor cursor = ((Cursor)getItem(position));
        long id = cursor.getLong(PHONE_ID_COLUMN_INDEX);
        return ContentUris.withAppendedId(Phones.CONTENT_URI, id);
    } 
7
CodeRank
This code example shows how to use the following methods:setProjection, setSortOrder, setUri
        mUnknownNameText = context.getText(android.R.string.unknownName);
    } 
 
    @Override 
    public void configureLoader(CursorLoader loader, long directoryId) {
        loader.setUri(People.CONTENT_URI);
        loader.setProjection(PEOPLE_PROJECTION);
        loader.setSortOrder(People.DISPLAY_NAME);
    } 
 
    @Override 
    public String getContactDisplayName(int position) {
        return ((Cursor)getItem(position)).getString(PERSON_DISPLAY_NAME_COLUMN_INDEX);
    } 
 
    public Uri getPersonUri(int position) {
        Cursor cursor = ((Cursor)getItem(position));
        long personId = cursor.getLong(PERSON_ID_COLUMN_INDEX);
        return ContentUris.withAppendedId(People.CONTENT_URI, personId);
    } 
7
CodeRank
This code example shows how to use the following methods:
    setListAdapter(adapter);
    getLoaderManager().initLoader(0, null, this);
  } 
 
  public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    return(new CursorLoader(this, CONTENT_URI, PROJECTION, null, null,
                            CallLog.Calls.DATE+" DESC"));
  } 
 
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.swapCursor(cursor);
  } 
 
  public void onLoaderReset(Loader<Cursor> loader) {
    adapter.swapCursor(null);
  } 
 
  @Override 
  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    long time=0;
7
CodeRank
This code example shows how to use the following methods:
 
    getLoaderManager().initLoader(0, null, this);
  } 
 
  public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    return(new CursorLoader(this, CalendarContract.Events.CONTENT_URI,
                            PROJECTION, null, null,
                            CalendarContract.Events.DTSTART));
  } 
 
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.swapCursor(cursor);
  } 
 
  public void onLoaderReset(Loader<Cursor> loader) {
    adapter.swapCursor(null);
  } 
 
  @Override 
  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
7
CodeRank
This code example shows how to use the following methods:
    setListAdapter(adapter);
    getLoaderManager().initLoader(0, null, this);
  } 
 
  public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    return(new CursorLoader(this, CONTENT_URI, PROJECTION, null, null,
                            CallLog.Calls.DATE+" DESC"));
  } 
 
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.swapCursor(cursor);
  } 
 
  public void onLoaderReset(Loader<Cursor> loader) {
    adapter.swapCursor(null);
  } 
 
  @Override 
  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    long time=0;
6
CodeRank
This code example shows how to use the following methods:
 
    getLoaderManager().initLoader(0, null, this);
  } 
 
  public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    return(new CursorLoader(this, CalendarContract.Events.CONTENT_URI,
                            PROJECTION, null, null,
                            CalendarContract.Events.DTSTART));
  } 
 
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.swapCursor(cursor);
  } 
 
  public void onLoaderReset(Loader<Cursor> loader) {
    adapter.swapCursor(null);
  } 
 
  @Override 
  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
6
CodeRank
This code example shows how to use the following methods:
        // Now create and return a CursorLoader that will take care of 
        // creating a Cursor for the data being displayed. 
        String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
                + Contacts.HAS_PHONE_NUMBER + "=1) AND ("
                + Contacts.DISPLAY_NAME + " != '' ))";
        return new CursorLoader(getActivity(), baseUri,
                CONTACTS_SUMMARY_PROJECTION, select, null,
                Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
    } 
 
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        // Swap the new cursor in.  (The framework will take care of closing the 
        // old cursor once we return.) 
        mAdapter.swapCursor(data);
 
        // The list should now be shown. 
        if (isResumed()) {
            setListShown(true);
        } else { 
            setListShownNoAnimation(true);
6
CodeRank
This code example shows how to use the following methods:setProjection, setSortOrder, setUri
        mUnknownNameText = context.getText(android.R.string.unknownName);
    } 
 
    @Override 
    public void configureLoader(CursorLoader loader, long directoryId) {
        loader.setUri(People.CONTENT_URI);
        loader.setProjection(PEOPLE_PROJECTION);
        loader.setSortOrder(People.DISPLAY_NAME);
    } 
 
    @Override 
    public String getContactDisplayName(int position) {
        return ((Cursor)getItem(position)).getString(PERSON_DISPLAY_NAME_COLUMN_INDEX);
    } 
 
    public Uri getPersonUri(int position) {
        Cursor cursor = ((Cursor)getItem(position));
        long personId = cursor.getLong(PERSON_ID_COLUMN_INDEX);
        return ContentUris.withAppendedId(People.CONTENT_URI, personId);
    } 
6
CodeRank
This code example shows how to use the following methods:
            // Now create and return a CursorLoader that will take care of 
            // creating a Cursor for the data being displayed. 
            String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
                    + Contacts.HAS_PHONE_NUMBER + "=1) AND ("
                    + Contacts.DISPLAY_NAME + " != '' ))";
            return new CursorLoader(getActivity(), baseUri,
                    CONTACTS_SUMMARY_PROJECTION, select, null,
                    Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
        } 
 
        public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
            // Swap the new cursor in.  (The framework will take care of closing the 
            // old cursor once we return.) 
            mAdapter.swapCursor(data);
 
            // The list should now be shown. 
            if (isResumed()) {
                setListShown(true);
            } else { 
                setListShownNoAnimation(true);
6
CodeRank

Related Android CursorLoader Questions & Answers:

Other Android CursorLoader Examples

49:	        // Now create and return a CursorLoader that will take care of
50:	        // creating a Cursor for the data being displayed.
51:	        return new CursorLoader(this, ContactsContract.Data.CONTENT_URI,
52:	                PROJECTION, SELECTION, null, null);
53:	    }

Read More

See Code Examples for Android CursorLoader Methods: