Java tutorial
//package com.java2s; import android.database.Cursor; import java.lang.reflect.Field; import java.util.Date; public class Main { private static Object getCursorValue(Cursor cursor, Field field, String columnName) { Class<?> fieldType = field.getType(); if (fieldType.equals(int.class) || field.equals(Integer.class)) { return cursor.getInt(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(String.class)) { return cursor.getString(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(long.class) || field.equals(Long.class)) { return cursor.getLong(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(float.class) || field.equals(Float.class)) { return cursor.getFloat(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(double.class) || field.equals(Double.class)) { return cursor.getDouble(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(long.class) || field.equals(Long.class)) { return cursor.getLong(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(Date.class)) { long time = cursor.getLong(cursor.getColumnIndex(columnName)); Date date = new Date(time); return date; } return cursor.getString(cursor.getColumnIndex(columnName)); } }