我猜你有一个20行的游标,现在你想用一个只包含一行的游标调用一个方法20次.以下是如何执行此操作的方法:
Cursor c = ...;// contains many rows
if(c.moveToFirst()){
String[] columns = c.getColumnNames();
while(!c.isAfterLast()){
MatrixCursor newCursor = new MatrixCursor(columns , 1);
MatrixCursor.RowBuilder b = newCursor.newRow();
for(String col: columns){
// in case all columns are of string type. But if they are
// different then see my comment below
b.add(c.getString(c.getColumnIndex(col)));
}
// invoke your listener here with newCursor
}
}
Run Code Online (Sandbox Code Playgroud)
如果列的数据类型不是String,该怎么办?
对于API> = 11:只需getType()在for循环中调用方法并使用switchstatement来调用适当的get方法.
对于API <11:运行与此类似的另一个查询PRAGMA table_info(my_table_name),然后只填充Map列名称并键入并在for循环中使用它.以下是您可以阅读此游标的方法/sf/answers/654808101/
| 归档时间: |
|
| 查看次数: |
4384 次 |
| 最近记录: |