Android游标?如何读取对象数据?

ang*_*gel 5 sqlite android casting cursor getstring

我知道Cursor有get String, Int等方法,但不是有些东西

mycursor.GetObject(index)
Run Code Online (Sandbox Code Playgroud)

我想创建一个返回一个对象的动态方法,我只抛出它.

或者可以 mycursor.GetString(index)用于任何类型? String,Float,Double,Long,Short, Blob,Int,等等

我可以使用例如a Float或a Int或任何类型并投射它?

例如

(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);
Run Code Online (Sandbox Code Playgroud)

会有用吗?我可以mycursor.GetString()用于任何类型吗?

dst*_*dst 4

您可以获取 column 的类型,然后从switch语句中调用适当的方法(并自行构建您要求的方法)。

getString正如文档所指定的那样,用于不同类型是不安全的:

当列值为 null 或列类型不是字符串类型时,结果以及此方法是否引发异常是实现定义的。