Cursor getColumnIndexOrThrow - 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 getColumnIndexOrThrow method.

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:getColumnIndexOrThrow, getCount, getString, moveToFirst
                        null,       // WHERE clause selection arguments (none) 
                        null); 		// Order-by clause (ascending by name) 
         
        if(cursor!=null)
        { 
        	int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        	if(  cursor.getCount()>0 && cursor.moveToFirst() )
            { 
            	imagePath = cursor.getString(column_index);
            } 
        } 
         
        return imagePath;
    } 
	 
	/** 
	 * 获取图片缩略图 
	 * 只有Android2.1以上版本支持 
	 * @param imgName 
	 * @param kind   MediaStore.Images.Thumbnails.MICRO_KIND 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, getColumnIndexOrThrow, getInt, getLong, moveToFirst
			// query for existing photo 
			String where = ContactsContract.Data.RAW_CONTACT_ID + " == " + 
				id + " AND " + Data.MIMETYPE + "=='" + 
				ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'"; 
			Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, null, where, null, null); 
			int idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Data._ID);
			int idphotoid = cursor.getColumnIndexOrThrow(ContactsContract.Data.PHOTO_FILE_ID);
			long photo_file_id = 0;
			if(cursor.moveToFirst()){ 
				photoRow = cursor.getInt(idIdx); 
				photo_file_id = cursor.getLong(idphotoid);
			}  
			cursor.close();
			if (photoRow < 0 && photo == null) {
				return; 
			} 
			 
			//long photo_file_id = MainActivity.GetInstance().GetPhotoStore().insert(displayPhoto, photo, true); 
			values.put(ContactsContract.Data.RAW_CONTACT_ID, 
					id); 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, getColumnIndexOrThrow, getString, moveToFirst
					String[] projection = { MediaStore.Images.Media.DATA };
					 
					Cursor cursor = managedQuery(selectedImageUri, projection, null, null, null);
					 
					if(cursor != null) {
						int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
						 
						cursor.moveToFirst();
						 
						String path = cursor.getString(column_index);
						 
						cursor.close();
						 
						BitmapFactory.Options bfo = new BitmapFactory.Options();
						bfo.inDither = true;
						bfo.inSampleSize = 2;
						 
						Bitmap bm = BitmapFactory.decodeFile(path, bfo);
						 
						if (bm != null) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close, getColumnIndexOrThrow, getString, moveToFirst
 
        Cursor cur = mResolver.query(uri, new String[] {
                Registry.ACCESS_SECRET, Registry.ACCESS_TOKEN 
        }, null, null, null); 
         
        assertTrue(cur.moveToFirst());
        assertEquals("mysec", cur.getString(cur.getColumnIndexOrThrow(Registry.ACCESS_SECRET)));
        assertEquals("mytok", cur.getString(cur.getColumnIndexOrThrow(Registry.ACCESS_TOKEN)));
        cur.close();
    } 
 
    /* SQL */ 
    private void clearDB() { 
        Cursor cur = mDB.rawQuery(
                "SELECT name FROM sqlite_master WHERE type=? AND name!=? AND name!=?", 
                new String[] {
                        "table", "android_metada", "sqlite_sequence" 
                }); 
        while (cur.moveToNext())
            mDB.execSQL("DELETE FROM " + cur.getString(0) + ";");
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getColumnIndexOrThrow, getCount, getInt, moveToFirst
            Consumers.IS_BANNED 
        }, Consumers.PACKAGE_NAME + "=?", new String[] {
            PACKAGE_UNDER_TEST
        }, null); 
 
        assertEquals(1, cur.getCount());
        assertTrue(cur.moveToFirst());
        assertEquals(0, cur.getInt(cur.getColumnIndexOrThrow(Consumers.IS_BANNED)));
    } 
 
    /* SQL */ 
    private void clearDB() { 
        Cursor cur = mDB.rawQuery(
                "SELECT name FROM sqlite_master WHERE type=? AND name!=? AND name!=?", 
                new String[] {
                        "table", "android_metada", "sqlite_sequence" 
                }); 
        while (cur.moveToNext())
            mDB.execSQL("DELETE FROM " + cur.getString(0) + ";");
        if (cur != null)
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getColumnIndexOrThrow, getString, moveToFirst
	 
	public static String getPath(Activity activity, Uri uri) {
	    String[] projection = { MediaStore.Images.Media.DATA };
	    Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
	    activity.startManagingCursor(cursor);
	    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
	    cursor.moveToFirst();
	    return cursor.getString(column_index);
	} 
	 
	public static int getExifOrientation(String filepath) {
		int degree = 0;
		ExifInterface exif = null;
		try { 
			exif = new ExifInterface(filepath);
		} catch (IOException ex) {
			ex.printStackTrace();
		} 
		if (exif != null) {
			int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getColumnIndexOrThrow
        // Check for database errors 
        if (data == null) {
            return; 
        } 
 
        mGenreIdIndex = data.getColumnIndexOrThrow(Audio.Genres._ID);
        mGenreNameIndex = data.getColumnIndexOrThrow(Audio.Genres.NAME);
        mGenreAdapter.changeCursor(data);
        mCursor = data;
    } 
 
    @Override 
    public void onLoaderReset(Loader<Cursor> loader) {
        if (mGenreAdapter != null)
            mGenreAdapter.changeCursor(null);
    } 
 
    @Override 
    public void onSaveInstanceState(Bundle outState) {
        outState.putAll(getArguments() != null ? getArguments() : new Bundle());
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Cursor getColumnIndexOrThrow Questions & Answers:

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