CursorWindow number of columns

末鹿安然 提交于 2019-12-11 09:18:15

问题


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:


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.



来源:https://stackoverflow.com/questions/11793059/cursorwindow-number-of-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!