Cursor getCount - 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 getCount 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, getCount, getString, moveToFirst
	             	new String[]{MediaStore.Images.Media.DATA}, // Which columns to return 
	             	MediaStore.Images.Media._ID+ "=?",       // Which rows to return 
	             	new String[]{String.valueOf(id)},       // Selection arguments
	             	null);// order 
		 
		if(cursor!=null && cursor.getCount()>0)
		{ 
			cursor.moveToFirst();
			String filepath = cursor.getString(0);
			cursor.close();
			int rotation = 0;
			 
			try 
			{ 
				ExifInterface exifInterface = new ExifInterface(filepath);
				int exifRotation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);
 
				if(exifRotation!=ExifInterface.ORIENTATION_UNDEFINED)
				{ 
					switch(exifRotation)
8
CodeRank
This code example shows how to use the following methods:getCount, getLong, getString, isAfterLast, isLast
        addJulie(); 
 
        assertThat(updateName("Belvedere")).isEqualTo(2); 
 
        Cursor cursor = database.query("table_name", new String[]{"id", "name"}, null, null, null, null, null);
        assertThat(cursor.moveToFirst()).isTrue();
        assertThat(cursor.getCount()).isEqualTo(2);
 
        assertIdAndName(cursor, 1234L, "Belvedere");
        assertThat(cursor.moveToNext()).isTrue();
 
        assertIdAndName(cursor, 1235L, "Belvedere");
        assertThat(cursor.isLast()).isTrue();
        assertThat(cursor.moveToNext()).isFalse();
        assertThat(cursor.isAfterLast()).isTrue();
        assertThat(cursor.moveToNext()).isFalse();
    } 
 
    @Test 
    public void testDelete() throws Exception { 

8
CodeRank
This code example shows how to use the following methods:getCount
    this.context = context;
    this.cursor = cursor;
  } 
 
  public int getCount() { 
    return cursor.getCount();
  } 
 
  public Object getItem(int index) {
    // Not used, so no point in retrieving it. 
    return null; 
  } 
 
  public long getItemId(int index) {
    return index;
  } 
 
  public View getView(int index, View view, ViewGroup viewGroup) {
    LinearLayout layout;
    if (view == null || !(view instanceof LinearLayout)) {
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: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
This code example shows how to use the following methods:close, getBlob, getCount, moveToFirst
                                                 appWidgetId);
                c = db.query(TABLE_PHOTOS, PHOTOS_PROJECTION, selection, null,
                        null, null, null, null); 
 
                if (c != null && LOGD) {
                    Log.d(TAG, "getPhoto query count=" + c.getCount());
                } 
 
                if (c != null && c.moveToFirst()) {
                    byte[] data = c.getBlob(INDEX_PHOTO_BLOB);
                    if (data != null) {
                        bitmap = BitmapFactory.decodeByteArray(data, 0,
                                data.length);
                    } 
                } 
            } catch (SQLiteException e) {
                Log.e(TAG, "Could not load photo from database", e);
            } finally { 
                if (c != null) {
                    c.close();

7
CodeRank
This code example shows how to use the following methods:getCount, moveToFirst
            null); 
    } 
 
    @Override 
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        if (0 >= data.getCount()) { return; }
        cursor = data;
        populateFields(); 
    } 
 
    @Override 
    public void onLoaderReset(Loader<Cursor> loader) {
        cursor = null;
    } 
 
    public void populateFields() { 
        if (null == cursor) { return; }
        cursor.moveToFirst();
        details.populateFields(cursor, from, to);
    } 

7
CodeRank

Related Cursor getCount Questions & Answers:

Other Cursor getCount Examples

172:			Cursor cursor = db.rawQuery("SELECT 1 FROM " + TABLE_RSS
173:					+ " WHERE rss_link = '" + rss_link + "'", new String[] {});
174:			boolean exists = (cursor.getCount() > 0);
175:			return exists;
176:		}

Read More

137:	
138:			// return count
139:			return cursor.getCount();
140:		}
141:

Read More

6:	
7:			// return count
8:			return cursor.getCount();
9:		}
10:

Read More

getCount Method Overview
Returns the numbers of rows in the cursor.
See Code Examples for other Android Cursor Methods: