How can I know how many columns there are on a CursorWindow
?
Why it has a getNumRows()
but no getNumColumns()
, despite having a setNumColumns()
?
Asked
Active
Viewed 171 times
1

m0skit0
- 25,268
- 11
- 79
- 127
-
1Why "in the name of God" are you dealing with a `CursorWindow` yourself in the first place? – CommonsWare Aug 03 '12 at 10:37
-
[Too long to explain here](http://stackoverflow.com/questions/11790893/passing-a-cursor-between-processes-parcelable-cursor) TLDR: because it's the only `Cursor`-thingy that implements `Parcelable`. – m0skit0 Aug 03 '12 at 12:58
1 Answers
2
I did it in this most horrible way:
/**
* 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;
}
I don't recommend using this. Just posting it if someone has the same problem and needs a quick solution to get moving.

m0skit0
- 25,268
- 11
- 79
- 127