Android Utililty Methods Cursor Read

List of utility methods to do Cursor Read

Description

The list of methods to do Cursor Read are organized into topic(s).

Method

intgetIntFromCursor(Cursor cursor, String columnName)
get Int From Cursor
return cursor.getInt(cursor.getColumnIndex(columnName));
StringgetStringFromCursor(Cursor cursor, String columnName)
get String From Cursor
return cursor.getString(cursor.getColumnIndex(columnName));
intgetPositionById(Cursor cursor, long theTargetId)
get Position By Id
int theWantedPosition = -1;
if (cursor != null && theTargetId > 0) {
    if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
            if (cursor.getLong(0) == theTargetId) {
                theWantedPosition = cursor.getPosition();
                break;
            cursor.moveToNext();
return theWantedPosition;
MatrixCursornewClosedCursor()
Creates new cursor, closes it and returns it ^
MatrixCursor cursor = new MatrixCursor(new String[0]);
cursor.close();
return cursor;
DategetDate(Cursor cursor, String columnName)
get Date
String dateString = cursor.getString(cursor
        .getColumnIndex(columnName));
if (dateString == null) {
    return null;
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
        Locale.ENGLISH);
Date date = null;
...