Cursor 应用

Cursor 使用[功能]android 提供了一个class 来对数据库的数据进行操作----Cursor 但是 Cursor 并不能自行

Cursor 使用

[功能]
android 提供了一个class 来对数据库的数据进行操作----Cursor
但是 Cursor 并不能自行构造 而只能从数据库查询而来 这就给使用带来诸多不便.

[原理]
1. 我们并不能把数据逐一地加入 Cursor 而只能根据数据库整体返回一个Cursor。
2. Cursor 的遍历


[使用]
1. 遍历
Cursor  c = ...;
for(c.moveToFirst(); ! c.isAfterLast(); c.moveToNext()){
//c...
}

2. 某一列序  //根据传入的列明 得到其序号
int i = c.getColumnIndex(String columnName)

3. 某一列值  //根据列序得到其值
String value = c.getString(int id)