Skip to content

Instantly share code, notes, and snippets.

@alexfu
Created June 30, 2015 11:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexfu/aa13a1168a8e13670842 to your computer and use it in GitHub Desktop.
Save alexfu/aa13a1168a8e13670842 to your computer and use it in GitHub Desktop.
Android database cursor extensions that simplify retrieval of typed values
import android.database.Cursor
/**
* CursorExtentions
*
* Android database cursor extensions that simplify retrieval of typed values
* @author alexfu
*/
fun Cursor.getInt(colName: String): Int {
return this.getInt(this.getColumnIndex(colName))
}
fun Cursor.getString(colName: String): String {
return this.getString(this.getColumnIndex(colName))
}
fun Cursor.getDouble(colName: String): Double {
return this.getDouble(this.getColumnIndex(colName))
}
fun Cursor.getFloat(colName: String): Float {
return this.getFloat(this.getColumnIndex(colName))
}
fun Cursor.getBlob(colName: String): ByteArray? {
return this.getBlob(this.getColumnIndex(colName))
}
fun Cursor.getLong(colName: String): Long {
return this.getLong(this.getColumnIndex(colName))
}
fun Cursor.getShort(colName: String): Short {
return this.getShort(this.getColumnIndex(colName))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment