angel angel - 5 months ago 29
Android Question

Android Cursor? how to read object data?

i know a

has method for get
String, Int
, etc
but isn't there somethings as


I want to create a dynamic method which returns an object and I only cast it.

or is it possible use
for any type?
String,Float,Double,Long,Short, Blob,Int

and I can use for example for a
or a
or any type and cast it?

for example

(Blob) newblob=mycursor.GetString(i_return_BloB);
(Int) newint=mycursor.GetString(i_return_Int);
(Float) newfloat=mycursor.GetString(i_return_Float);
(Double) newdouble=mycursor.GetString(i_return_Double);
(Long) newlong=mycursor.GetString(i_return_long);
(Short) newshort=mycursor.GetString(i_return_short);

would it work?
could i use
for any type?

dst dst

You can get the type of a column, and then call the appropiate method from a switch statement (and build the method you're asking for by yourself).

Using getString for different types is not safe, as the docs specify:

The result and whether this method throws an exception when the column value is null or the column type is not a string type is implementation-defined.