Android Cursor - 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 Cursor class.

This code example shows how to use the following methods:getString, moveToPosition
    setListAdapter(new BookmarkAdapter(this, cursor));
  } 
 
  @Override 
  protected void onListItemClick(ListView l, View view, int position, long id) {
    if (cursor.moveToPosition(position)) {
      Intent intent = new Intent();
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      intent.putExtra(Browser.BookmarkColumns.TITLE, cursor.getString(TITLE_COLUMN));
      intent.putExtra(Browser.BookmarkColumns.URL, cursor.getString(URL_COLUMN));
      setResult(RESULT_OK, intent);
    } else { 
      setResult(RESULT_CANCELED);
    } 
    finish();
  } 
} 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInt, getString
        mContactAccessor = ContactAccessor.getInstance();
    } 
 
    @Override 
    public final CharSequence convertToString(Cursor cursor) {
        String name = cursor.getString(RecipientsAdapter.NAME_INDEX);
        int type = cursor.getInt(RecipientsAdapter.TYPE_INDEX);
        String number = cursor.getString(RecipientsAdapter.NUMBER_INDEX).trim();
 
        String label = cursor.getString(RecipientsAdapter.LABEL_INDEX);
        CharSequence displayLabel = mContactAccessor.phoneTypeToString(mContext, type, label);
 
        if (number.length() == 0) {
            return number;
        } 
 
        if (name == null) {
            name = "";
        } else { 
            // Names with commas are the bane of the recipient editor's existence. 

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getColumnIndex
 
        try { 
            super.changeCursor(c);
 
            if (c != null) {
                mText1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1);
                mText2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2);
                mText2UrlCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2_URL);
                mIconName1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_1);
                mIconName2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_2);
                mFlagsCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_FLAGS);
            } 
        } catch (Exception e) {
            Log.e(LOG_TAG, "error changing cursor and caching columns", e);
        } 
    } 
 
    /** 
     * Tags the view with cached child view look-ups. 
     */ 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, getColumnIndexOrThrow, getCount, getLong, moveToFirst
This code example shows how to use the following methods:close, getColumnIndexOrThrow, getLong, getString, moveToFirst
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getColumnIndexOrThrow, getString, isAfterLast, moveToPosition
                args, R.string.user_dict_settings_add_dialog_title, null, null, 0);
    } 
 
    private String getWord(final int position) {
        if (null == mCursor) return null;
        mCursor.moveToPosition(position);
        // Handle a possible race-condition 
        if (mCursor.isAfterLast()) return null;
 
        return mCursor.getString(
                mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD));
    } 
 
    private String getShortcut(final int position) {
        if (null == mCursor) return null;
        mCursor.moveToPosition(position);
        // Handle a possible race-condition 
        if (mCursor.isAfterLast()) return null;
 
        return mCursor.getString(

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInt, getLong, getString, isNull
 
    /** @inheritdoc */ 
    @Override 
    public SpecialNamesEntity readEntity(Cursor cursor, int offset) {
        SpecialNamesEntity entity = new SpecialNamesEntity( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // count
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // select
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // sum
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // avg
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // join
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // distinct
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // on
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // index
            cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9) // order
        ); 
        return entity;
    } 
      
    /** @inheritdoc */ 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, getString, moveToFirst
    } 
 
    private static String getCalendarId(Uri uri, ContentResolver cr) {
        Cursor calendar = cr.query(uri, new String[] { CALENDAR_ID_COLUMN }, null, null, null);
        try { 
            calendar.moveToFirst();
            return calendar.getString(0);
        } catch (CursorIndexOutOfBoundsException e) {
            return null; 
        } finally  { 
            calendar.close();
        } 
    } 
 
    @SuppressWarnings("nls") 
    public static boolean deleteTaskEvent(Task task) {
        boolean eventDeleted = false;
        String uri;
        if(task.containsNonNullValue(Task.CALENDAR_URI))
            uri = task.getValue(Task.CALENDAR_URI);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getColumnIndex, getInt
		return bookmark;
	} 
		 
	private void readScreenSettings(BookmarkBase bookmark, Cursor cursor) {
		BookmarkBase.ScreenSettings screenSettings = bookmark.getScreenSettings();
		screenSettings.setColors(cursor.getInt(cursor.getColumnIndex("screenColors")));
		screenSettings.setResolution(cursor.getInt(cursor.getColumnIndex("screenResolution")));
		screenSettings.setWidth(cursor.getInt(cursor.getColumnIndex("screenWidth")));
		screenSettings.setHeight(cursor.getInt(cursor.getColumnIndex("screenHeight")));		
	} 
	 
	private void readPerformanceFlags(BookmarkBase bookmark, Cursor cursor) {
		BookmarkBase.PerformanceFlags perfFlags = bookmark.getPerformanceFlags();
		perfFlags.setRemoteFX(cursor.getInt(cursor.getColumnIndex("performanceRemoteFX")) == 0 ? false : true);
		perfFlags.setWallpaper(cursor.getInt(cursor.getColumnIndex("performanceWallpaper")) == 0 ? false : true);
		perfFlags.setTheming(cursor.getInt(cursor.getColumnIndex("performanceTheming")) == 0 ? false : true);
		perfFlags.setFullWindowDrag(cursor.getInt(cursor.getColumnIndex("performanceFullWindowDrag")) == 0 ? false : true);
		perfFlags.setMenuAnimations(cursor.getInt(cursor.getColumnIndex("performanceMenuAnimations")) == 0 ? false : true);
		perfFlags.setFontSmoothing(cursor.getInt(cursor.getColumnIndex("performanceFontSmoothing")) == 0 ? false : true);
		perfFlags.setDesktopComposition(cursor.getInt(cursor.getColumnIndex("performanceDesktopComposition")) == 0 ? false : true);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, getInt, moveToNext
				"select exists(select _id from Events)" 
				; 
 
			c = db.rawQuery(sql, null);
 
			if(c.moveToNext()) {
				result = c.getInt(0) != 0;
			} 
		} catch (SQLException e) {
			Log.e(TAG, "Error determining if there are events to send: ", e);
		} finally { 
			if (c != null) {
				c.close();
			} 
			if (db != null) {
				db.close();
			} 
		} 
 
		return result;
8
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android Cursor Questions & Answers:

Other Android Cursor Examples

13:	  public void onCreate(Bundle savedInstanceState) {
14:	    super.onCreate(savedInstanceState);
15:	    Cursor mCursor = getContacts();
16:	    startManagingCursor(mCursor);
17:	    // now create a new list adapter bound to the cursor.
-
35:	  }
36:	
37:	  private Cursor getContacts() {
38:	    // Run query
39:	    Uri uri = ContactsContract.Contacts.CONTENT_URI;

Read More

2:			String countQuery = "SELECT  * FROM " + TABLE_CONTACTS;
3:			SQLiteDatabase db = this.getReadableDatabase();
4:			Cursor cursor = db.rawQuery(countQuery, null);
5:			cursor.close();
6:

Read More

9:			Log.e(LOG, selectQuery);
10:	
11:			Cursor c = db.rawQuery(selectQuery, null);
12:	
13:			if (c != null)

Read More

2:			SQLiteDatabase db = this.getReadableDatabase();
3:	
4:			Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
5:					KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
6:					new String[] { String.valueOf(id) }, null, null, null, null);

Read More

1:	public class ListViewLoader extends ListActivity
2:	        implements LoaderManager.LoaderCallbacks<Cursor> {
3:	
4:	    // This is the Adapter being used to display the list's data
-
46:	
47:	    // Called when a new Loader needs to be created
48:	    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
49:	        // Now create and return a CursorLoader that will take care of
50:	        // creating a Cursor for the data being displayed.
-
54:	
55:	    // Called when a previously created loader has finished loading
56:	    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
57:	        // Swap the new cursor in.  (The framework will take care of closing the
58:	        // old cursor once we return.)
-
54:	
55:	    // Called when a previously created loader has finished loading
56:	    public void onLoadFinished(Loader loader, Cursor data) {
57:	        // Swap the new cursor in.  (The framework will take care of closing the
58:	        // old cursor once we return.)
-
61:	
62:	    // Called when a previously created loader is reset, making the data unavailable
63:	    public void onLoaderReset(Loader<Cursor> loader) {
64:	        // This is called when the last Cursor provided to onLoadFinished()
65:	        // above is about to be closed.  We need to make sure we are no

Read More

See Code Examples for Android Cursor Methods: