在使用游标 Cursor 是获取列值的时候最好确定列名是否与数据库一至
-
if(localcursor.moveToFirst())
-
{
-
do {
-
Item item = new Item();
-
//item.id = localcursor.getInt(1);
-
item.setDid(localcursor.getInt(2));
-
item.setTitle(localcursor.getString(3));
-
item.setType(localcursor.getString(4));
-
item.setCollection(localcursor.getInt(5));
-
item.setAnswer(localcursor.getString(6));
-
ilist.add(item);
-
} while (localcursor.moveToNext());
-
}
这样写,可能获取的值不是与你想象中的一样。可能会错开。
最好是下面这种写法
-
if(localcursor.moveToFirst())
-
{
-
do {
-
Item item = new Item();
-
//item.id = localcursor.getInt(1);
-
item.setDid(localcursor.getInt(localcursor.getColumnIndex(StaticPerson.I_DID)));
-
item.setTitle(localcursor.getString(localcursor.getColumnIndex(StaticPerson.I_TITLE)));
-
item.setType(localcursor.getString(localcursor.getColumnIndex(StaticPerson.I_TYPE)));
-
item.setCollection(localcursor.getInt(localcursor.getColumnIndex(StaticPerson.I_COLLECTION)));
-
item.setAnswer(localcursor.getString(localcursor.getColumnIndex(StaticPerson.I_ANSWER)));
-
ilist.add(item);
-
} while (localcursor.moveToNext());
-
}
这样更加准确的获取每个列的值
阅读(432) | 评论(0) | 转发(0) |