我如何知道 CursorWindow
上有多少列?
为什么它有 getNumRows()
而没有 getNumColumns()
,尽管有 setNumColumns()
?
最佳答案
我用这种最可怕的方式做到了:
/**
* Get the number of columns of this CursorWindow. The CursorWindow has to
* have at least one row.
*/
public static int getCursorWindowNumCols(CursorWindow window) {
// Ugly hack...
int j = 0;
while (true) {
try {
window.getString(0, j);
} catch (IllegalStateException e) {
break;
} catch (SQLException e) {
// It's a BLOB!
}
j++;
}
return j;
}
我不推荐使用这个。如果有人遇到同样的问题并且需要快速解决方案才能开始行动,只需张贴即可。
关于android - CursorWindow 的列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11793059/