Example usage for android.database Cursor getColumnIndex

List of usage examples for android.database Cursor getColumnIndex

Introduction

In this page you can find the example usage for android.database Cursor getColumnIndex.

Prototype

int getColumnIndex(String columnName);

Source Link

Document

Returns the zero-based index for the given column name, or -1 if the column doesn't exist.

Usage

From source file:Main.java

public static byte[] getBlob(@NonNull Cursor cursor, @NonNull String columnName) {
    return cursor.getBlob(cursor.getColumnIndex(columnName));
}

From source file:Main.java

private static String getString(final Cursor cursor, final String field, final String defValue) {
    if (cursor.getColumnIndex(field) >= 0) {
        return cursor.getString(cursor.getColumnIndex(field));
    } else {//from ww  w .ja va  2s .co  m
        return defValue;
    }
}

From source file:Main.java

public static long getLong(@NonNull Cursor cursor, @NonNull String columnName) {
    return cursor.getLong(cursor.getColumnIndex(columnName));
}

From source file:Main.java

public static short getShort(@NonNull Cursor cursor, @NonNull String columnName) {
    return cursor.getShort(cursor.getColumnIndex(columnName));
}

From source file:Main.java

public static float getFloat(@NonNull Cursor cursor, @NonNull String columnName) {
    return cursor.getFloat(cursor.getColumnIndex(columnName));
}

From source file:Main.java

public static double getDouble(@NonNull Cursor cursor, @NonNull String columnName) {
    return cursor.getDouble(cursor.getColumnIndex(columnName));
}

From source file:Main.java

private static int getInt(final Cursor cursor, final String field, final int defValue) {
    if (cursor.getColumnIndex(field) >= 0) {
        return cursor.getInt(cursor.getColumnIndex(field));
    } else {//w  ww  . j a  va  2s  . com
        return defValue;
    }
}

From source file:Main.java

/**
 * Retrieves a {@link String} value from the {@link Cursor}.
 * //from   ww  w . j  a v a  2 s .  c  om
 * @param cursor
 *            The {@link Cursor} pointing at the correct record.
 * @param strColName
 *            The name of the column to retrieve.
 * @return A {@link String} containing the value.
 */
public static String getString(final Cursor cursor, final String strColName) {
    String strResult = cursor.getString(cursor.getColumnIndex(strColName));
    if (strResult == null)
        strResult = "";

    return strResult;
}

From source file:Main.java

public static Object cursorValue(String column, Cursor cr) {
    Object value = false;/*ww w .j  ava  2  s  .c om*/
    int index = cr.getColumnIndex(column);
    switch (cr.getType(index)) {
    case Cursor.FIELD_TYPE_NULL:
        value = false;
        break;
    case Cursor.FIELD_TYPE_STRING:
        value = cr.getString(index);
        break;
    case Cursor.FIELD_TYPE_INTEGER:
        value = cr.getInt(index);
        break;
    case Cursor.FIELD_TYPE_FLOAT:
        value = cr.getFloat(index);
        break;
    case Cursor.FIELD_TYPE_BLOB:
        value = cr.getBlob(index);
        break;
    }
    return value;
}

From source file:Main.java

public static String getRealPathFromURI(Context ctx, Uri uri) {
    Cursor cursor = ctx.getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();// w w  w . j a v  a  2 s. c  o  m
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(idx);
}