Cursor getColumnIndex - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Cursor getColumnIndex method.

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
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
This code example shows how to use the following methods:getColumnIndex, getInt, getLong, getString, isNull
        final boolean validIcon = mResPackage != null && mIconRes != -1;
        return validIcon ? pm.getDrawable(mResPackage, mIconRes, null) : null;
    } 
 
    private static String getString(Cursor cursor, String columnName) {
        return cursor.getString(cursor.getColumnIndex(columnName));
    } 
 
    private static int getInt(Cursor cursor, String columnName) {
        return cursor.getInt(cursor.getColumnIndex(columnName));
    } 
 
    private static int getInt(Cursor cursor, String columnName, int missingValue) {
        final int columnIndex = cursor.getColumnIndex(columnName);
        return cursor.isNull(columnIndex) ? missingValue : cursor.getInt(columnIndex);
    } 
 
    private static long getLong(Cursor cursor, String columnName, long missingValue) {
        final int columnIndex = cursor.getColumnIndex(columnName);
        return cursor.isNull(columnIndex) ? missingValue : cursor.getLong(columnIndex);

8
CodeRank
This code example shows how to use the following methods:close, getColumnIndex, getCount, getInt, moveToFirst
		String fileName = null;
		String[] columns = {"FileName"};
		String[] selectionArgs = {playlistName};
		Cursor query = db.query(TABLE_PLAYLIST, columns, "PlaylistName = ?", selectionArgs, null, null, null);
	 
		if(query != null && query.getCount() > 0){
			int columnIndex = query.getColumnIndex("FileName");
			query.moveToFirst();
			int file_id = query.getInt(columnIndex);
			fileName = ""+file_id+SJP_EXT;
		} 
	 
		query.close();
	 
		return fileName;
	} 
 
	private SQLiteDatabase getDb(){
		return mActivity.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
	} 
8
CodeRank
This code example shows how to use the following methods:getColumnIndex, getString, moveToFirst
        String name = "nullone";
 
        database.execSQL("insert into exectable (first_column, name) values (?,?);", new String[]{null, name});
 
        Cursor cursor = database.rawQuery("select * from exectable WHERE `name` = ?", new String[]{name});
        cursor.moveToFirst();
        int firstIndex = cursor.getColumnIndex("first_column");
        int nameIndex = cursor.getColumnIndex("name");
        assertThat(cursor.getString(nameIndex)).isEqualTo(name);
        assertThat(cursor.getString(firstIndex)).isEqualTo((String) null);
 
    } 
 
    @Test(expected = Exception.class) 
    public void testExecSQLInsertNullShouldBeException() throws Exception { 
        //this inserts null in android, but it when it happens it is likely an error.  H2 throws an exception.  So we'll make Robolectric expect an Exception so that the error can be found. 
 
        database.delete("exectable", null, null);
 
        Cursor cursor = database.rawQuery("select * from exectable", null);
8
CodeRank
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. 
     */ 
8
CodeRank
This code example shows how to use the following methods:close, getColumnIndex, getCount, getString, moveToFirst
	} 
	 
	public Bundle getUser(long id) throws SQLException {
		Cursor cursor = db.query(true, USER_TABLE, new String[] {KEY_USERNAME, KEY_PASSWORD}, KEY_COREIDREFERENCE + "=" + id, null, null, null, null, null);
		Bundle b = null;
		if (cursor != null && cursor.getCount() > 0) {
			b = new Bundle();
			cursor.moveToFirst();
			b.putString(KEY_USERNAME, cursor.getString(cursor.getColumnIndex(KEY_USERNAME)));
			b.putString(KEY_PASSWORD, cursor.getString(cursor.getColumnIndex(KEY_PASSWORD)));
			cursor.close(); 
		} 
		return b;
	} 
	 
	public void deleteUser(long coreId) {
		db.delete(USER_TABLE, KEY_COREIDREFERENCE + "=" + coreId, null);
	} 
 
	public void cleanupEvents(Integer[] bufferids) {
8
CodeRank
This code example shows how to use the following methods:close, getColumnIndex, getCount, getString, moveToFirst
                return new File(uri.getPath());
            case URI_TYPE_CONTENT: {
                Cursor cursor = contentResolver.query(uri, LOCAL_FILE_PROJECTION, null, null, null);
                if (cursor != null) {
                    try { 
                        int columnIndex = cursor.getColumnIndex(LOCAL_FILE_PROJECTION[0]);
                        if (columnIndex != -1 && cursor.getCount() > 0) {
                            cursor.moveToFirst();
                            String realPath = cursor.getString(columnIndex);
                            if (realPath != null) {
                                return new File(realPath);
                            } 
                        } 
                    } finally { 
                        cursor.close();
                    } 
                } 
            } 
        } 
        return null; 
7
CodeRank
This code example shows how to use the following methods:getColumnIndex, getCount, getInt, moveToFirst
                AwfulPost.THREAD_ID+"=? AND "+AwfulPost.POST_INDEX+"<=?", 
                AwfulProvider.int2StrArray(threadId, postIndex));
 
        //update unread count 
        Cursor threadData = resolv.query(ContentUris.withAppendedId(AwfulThread.CONTENT_URI, threadId), AwfulProvider.ThreadProjection, null, null, null);
        if(threadData.getCount()>0 && threadData.moveToFirst()){
            ContentValues thread_update = new ContentValues();
            thread_update.put(AwfulThread.UNREADCOUNT, threadData.getInt(threadData.getColumnIndex(AwfulThread.POSTCOUNT)) - postIndex);
            resolv.update(AwfulThread.CONTENT_URI,
                    thread_update,
                    AwfulThread.ID + "=?", 
                    AwfulProvider.int2StrArray(threadId));
        } 
        return null; 
    } 
 
    @Override 
    protected boolean handleError(AwfulError error, Document doc) {
        return error.isCritical();
    } 
7
CodeRank
This code example shows how to use the following methods:getColumnIndex, getInt, getLong, getString, isNull
        final boolean validIcon = mResPackage != null && mIconRes != -1;
        return validIcon ? pm.getDrawable(mResPackage, mIconRes, null) : null;
    } 
 
    private static String getString(Cursor cursor, String columnName) {
        return cursor.getString(cursor.getColumnIndex(columnName));
    } 
 
    private static int getInt(Cursor cursor, String columnName) {
        return cursor.getInt(cursor.getColumnIndex(columnName));
    } 
 
    private static int getInt(Cursor cursor, String columnName, int missingValue) {
        final int columnIndex = cursor.getColumnIndex(columnName);
        return cursor.isNull(columnIndex) ? missingValue : cursor.getInt(columnIndex);
    } 
 
    private static long getLong(Cursor cursor, String columnName, long missingValue) {
        final int columnIndex = cursor.getColumnIndex(columnName);
        return cursor.isNull(columnIndex) ? missingValue : cursor.getLong(columnIndex);

8
CodeRank

Related Cursor getColumnIndex Questions & Answers:

Other Cursor getColumnIndex Examples

130:	
131:			Todo td = new Todo();
132:			td.setId(c.getInt(c.getColumnIndex(KEY_ID)));
133:			td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
134:			td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
-
131:			Todo td = new Todo();
132:			td.setId(c.getInt(c.getColumnIndex(KEY_ID)));
133:			td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
134:			td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
135:	
-
132:			td.setId(c.getInt(c.getColumnIndex(KEY_ID)));
133:			td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
134:			td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
135:	
136:			return td;
-
153:				do {
154:					Todo td = new Todo();
155:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
156:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
157:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
-
154:					Todo td = new Todo();
155:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
156:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
157:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
158:	
-
155:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
156:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
157:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
158:	
159:					// adding to todo list
-
186:				do {
187:					Todo td = new Todo();
188:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
189:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
190:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
-
187:					Todo td = new Todo();
188:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
189:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
190:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
191:	
-
188:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
189:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
190:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
191:	
192:					// adding to todo list
-
271:				do {
272:					Tag t = new Tag();
273:					t.setId(c.getInt((c.getColumnIndex(KEY_ID))));
274:					t.setTagName(c.getString(c.getColumnIndex(KEY_TAG_NAME)));
275:	
-
272:					Tag t = new Tag();
273:					t.setId(c.getInt((c.getColumnIndex(KEY_ID))));
274:					t.setTagName(c.getString(c.getColumnIndex(KEY_TAG_NAME)));
275:	
276:					// adding to tags list

Read More

14:				do {
15:					Tag t = new Tag();
16:					t.setId(c.getInt((c.getColumnIndex(KEY_ID))));
17:					t.setTagName(c.getString(c.getColumnIndex(KEY_TAG_NAME)));
18:	
-
15:					Tag t = new Tag();
16:					t.setId(c.getInt((c.getColumnIndex(KEY_ID))));
17:					t.setTagName(c.getString(c.getColumnIndex(KEY_TAG_NAME)));
18:	
19:					// adding to tags list

Read More

19:				do {
20:					Todo td = new Todo();
21:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
22:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
23:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
-
20:					Todo td = new Todo();
21:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
22:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
23:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
24:	
-
21:					td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
22:					td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
23:					td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));
24:	
25:					// adding to todo list

Read More

getColumnIndex Method Overview
Returns the zero-based index for the given column name, or -1 if the column doesn't exist.
See Code Examples for other Android Cursor Methods: