CursorWindow number of columns

2019-08-03 05:31发布

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

1条回答
We Are One
2楼-- · 2019-08-03 06:09

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.

查看更多
登录 后发表回答