Example usage for android.database Cursor getString

List of usage examples for android.database Cursor getString

Introduction

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

Prototype

String getString(int columnIndex);

Source Link

Document

Returns the value of the requested column as a String.

Usage

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 {/* w  w w .  ja  va  2s.  c  o  m*/
        return defValue;
    }
}

From source file:Main.java

public static String gText(Cursor cursor, String columeName) {
    String val = null;
    if (cursor.getColumnIndex(columeName) != -1) {
        val = cursor.getString(cursor.getColumnIndex(columeName));
    }/*from www . j av  a 2 s .com*/
    return val;
}

From source file:Main.java

private static void fillArray(Cursor cursor, String[] array) {
    for (int i = 0; i < array.length; i++) {
        array[i] = cursor.getString(i);
    }//from w w  w  .ja v  a  2 s. c om
}

From source file:Main.java

/**
 * Returns the system default ringtone URI {@link Uri}, or
 * the first available ringtone when the system default
 * does not exist (usually tablets)./* w  w w  .  ja  v a 2 s.  co  m*/
 *
 * @param ctx the {@link Context}
 * @return Uri ringtone URI
 */
public static Uri getDefaultRingtoneUri(Context ctx, int type) {
    Uri uri;

    uri = RingtoneManager.getActualDefaultRingtoneUri(ctx, type);

    if (uri == null) {
        // The default ringtone doesn't exist - probably a tablet
        // Return the first available
        RingtoneManager rm = new RingtoneManager(ctx);
        rm.setType(type);

        Cursor cursor = rm.getCursor();
        cursor.moveToFirst();

        String idString = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
        String uriString = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);

        uri = Uri.parse(uriString + '/' + idString);

        cursor.close();

        return uri;
    } else {
        // Return system default ringtone
        return uri;
    }
}

From source file:Main.java

public static void bindText(View view, Cursor cursor, int resource, String column) {
    TextView textView = (TextView) view.findViewById(resource);
    textView.setText(cursor.getString(cursor.getColumnIndex(column)));
}

From source file:Main.java

public static String getFileNameFromUri(Uri uri, Activity activity) {
    String[] projection = { MediaStore.Images.ImageColumns.DISPLAY_NAME };
    String fileName = null;/*  www  .  ja va2s  . c o m*/
    Cursor c = activity.managedQuery(uri, projection, null, null, null);
    if (c != null && c.moveToFirst()) {
        fileName = c.getString(0);
    }
    return fileName;

}

From source file:Main.java

public static String query(Context context, Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null,
            null);//from   ww  w.j  a v a  2 s .  c o m
    cursor.moveToNext();
    return cursor.getString(cursor.getColumnIndex(ImageColumns.DATA));
}

From source file:Main.java

public static String query(Context context, Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, new String[] { MediaColumns.DATA }, null, null,
            null);//from w  w w  .ja va2  s .c  om
    cursor.moveToNext();
    return cursor.getString(cursor.getColumnIndex(MediaColumns.DATA));
}

From source file:Main.java

public static List<String> listAlldir(Context cxt) {
    Intent intent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    Uri uri = intent.getData();//  w w w  .j  a va  2s  . c o m
    List<String> list = new ArrayList<String>();
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = cxt.getContentResolver().query(uri, proj, null, null, null);
    while (cursor.moveToNext()) {
        String path = cursor.getString(0);
        list.add(new File(path).getAbsolutePath());
    }
    return list;
}

From source file:Main.java

/**
 * to query columns names of a Table from database
 * @author wajdihh//from www .ja  v  a2  s.com
 * @param pDatabase
 * @param pTableName
 * @return list of columns
 */
public static ArrayList<String> getTableColumnsNames(SQLiteDatabase pDatabase, String pTableName) {
    ArrayList<String> lListOfColumns = new ArrayList<String>();
    Cursor lCursor = pDatabase.rawQuery("PRAGMA table_info(" + pTableName + ")", null);
    while (lCursor.moveToNext())
        lListOfColumns.add(lCursor.getString(1));
    return lListOfColumns;
}