android中cursor对象的使用

cursor对象是使用行来存储数据的,你要使用它获得数据,就必须知道每一列的数据名称以及他的数据类型才能获得对象数据

常见的方法:

.close()关闭资源:记住,所有的资源对象使用完成后都要主动关闭才行

.moveToNext()移动到下一行

.moveToFirst()移动到第一行

.getColumnCount()返回列数

.getColumnIndex("")返回列名称

.getString(.getColumnIndex(""))返回获得列名称对应的数据

if(cursor!=null)
    while(cursor.moveToNext()){
        String a=cursor.getString(cursor.getColumnIndex("column1"));
        int b=cursor.getInt(cursor.getcolumnIndex("column2"));
    }
    cursor.close();
}

 

posted @ 2016-05-09 19:04  风雨缠舟  阅读(492)  评论(0编辑  收藏  举报