Example usage for android.database Cursor getCount

List of usage examples for android.database Cursor getCount

Introduction

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

Prototype

int getCount();

Source Link

Document

Returns the numbers of rows in the cursor.

Usage

From source file:Main.java

public static boolean isCursorEmpty(Cursor cursor) {
    return cursor == null || cursor.getCount() == 0;
}

From source file:Main.java

public static boolean isCursorRight(Cursor cursor) {
    if (cursor == null || cursor.getCount() <= 0) {
        return false;
    }/*w  ww .  j  a  v a 2 s.c o  m*/
    return true;
}

From source file:Main.java

/**
 * Checks if the passed cursor has at least 1 record.
 * @param cursor The {@link Cursor} to check.
 * @return <code>true</code> if the {@link Cursor} has at least 1 record,
 * <code>false</code> if not.
 */// w  ww  .  j a  v a 2 s  .c om
public static boolean hasRecords(final Cursor cursor) {
    return (isOpen(cursor)) && (cursor.getCount() > 0);
}

From source file:Main.java

public static long[] readIds(Cursor cursor) {
    long[] arr = new long[cursor.getCount()];
    int count = 0;
    try {//  w  w  w .  j a  va  2  s  . c  o m
        while (cursor.moveToNext()) {
            arr[count++] = cursor.getLong(0);
        }
    } finally {
        cursor.close();
    }
    return arr;
}

From source file:Main.java

public static boolean isCursorEmpty(Cursor cursor) {
    return (cursor == null || cursor.isClosed() || cursor.getCount() == 0);
}

From source file:Main.java

public static LinkedList<Integer> retrieveIntegerFromCursor(Cursor cursor, String columnName) {
    if (null == cursor || 0 == cursor.getCount()) {
        return new LinkedList<Integer>();
    }/*  ww  w. j av a2 s .  c o m*/

    LinkedList<Integer> ids = new LinkedList<Integer>();

    try {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            int id = cursor.getInt(cursor.getColumnIndexOrThrow(columnName));
            ids.add(new Integer(id));
        }
    } catch (Exception e) {
        //do nothing.
    } finally {
        cursor.close();
    }

    return ids;
}

From source file:Main.java

public static ArrayList<HashMap<String, String>> cursorToHashMap(Cursor cursor) {

    if (cursor != null) {
        int cursorCount = cursor.getCount();
        int columnCount;
        ArrayList<HashMap<String, String>> cursorData = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> rowHashMap;
        for (int i = 0; i < cursorCount; i++) {
            cursor.moveToPosition(i);/*  w ww  .j a  va2 s  . c o m*/
            rowHashMap = new HashMap<String, String>();
            columnCount = cursor.getColumnCount();
            for (int j = 0; j < columnCount; j++) {
                rowHashMap.put(cursor.getColumnName(j), cursor.getString(j));
            }
            cursorData.add(rowHashMap);
        }
        cursor.close();

        return cursorData;
    } else {
        return null;
    }
}

From source file:Main.java

public static int getContactIdFromPhoneNumber(final Context context, final String number) {
    final Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    final String[] projection = { PhoneLookup._ID };
    final Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
    if (c.getCount() > 0) {
        c.moveToFirst();/*from   w  ww  .  ja  v a  2  s.c  o m*/
        return c.getInt(0);
    } else {
        return -1;
    }
}

From source file:Main.java

public static java.util.List<String> getLabelsFromInt(Cursor c) {
    c.moveToFirst();/*from  w w  w. j a  v  a 2 s  .  c om*/
    ArrayList<String> res = new ArrayList<>();
    for (int i = 0; i < c.getCount(); i++) {
        res.add(i, String.valueOf(c.getInt(0)));
        c.moveToNext();
    }
    return res;
}

From source file:Main.java

public static boolean hasDraftsToMigrate(Context context) {
    try {/*w ww .  j av  a  2s. c  om*/
        SQLiteDatabase db = context.openOrCreateDatabase(DEPRECATED_DATABASE_NAME, 0, null);

        String byString = "localDraft=1 OR isLocalChange=1";
        Cursor c = db.query(DEPRECATED_POSTS_TABLE, null, byString, null, null, null, null);
        if (c.getCount() > 0) {
            c.close();
            return true;
        }
        c.close();
        return false;
    } catch (SQLException e) {
        return false;
    }
}