Is there any way to identify the datatype of a column in a cursor in Android. The cursor object has a number of methods to get the columnname, column value.
I want t
I didn't tested yet but, try to use cursor.getType(i)
Like this:
public static List resultSetToArrayListAndroid(Cursor cursor) throws SQLException {
int columns = cursor.getColumnCount();
ArrayList list = new ArrayList();
while (cursor.moveToNext()) {
HashMap row = new HashMap(columns);
for (int i = 1; i <= columns; ++i) {
switch (cursor.getType(i)) {
case Cursor.FIELD_TYPE_FLOAT:
row.put(cursor.getColumnName(i), cursor.getFloat(i));
break;
case Cursor.FIELD_TYPE_INTEGER:
row.put(cursor.getColumnName(i), cursor.getInt(i));
break;
case Cursor.FIELD_TYPE_STRING:
row.put(cursor.getColumnName(i), cursor.getString(i));
break;
}
}
list.add(row);
}
return list;
}