android中用cursor游标取数据库数据
cursor=db.query("Bok",.......);if(cursor.moveToFirst()){do{Stringname=cursor.getStrin...
cursor = db.query("Bok",.......);
if(cursor.moveToFirst()){
do{
String name = cursor.getString(cursor.getColumnIndex("fromuser"));
String toname = cursor.getString(cursor.getColumnIndex("touser"));
String content = cursor.getString(cursor.getColumnIndex("content"));
String date = cursor.getString(cursor.getColumnIndex("date"));
String type = cursor.getString(cursor.getColumnIndex("type"));
}while(cursor.moveToNext());
}
假如游标到了第二个位置,现在取name 怎么判断与第一个位置中的name相同 展开
if(cursor.moveToFirst()){
do{
String name = cursor.getString(cursor.getColumnIndex("fromuser"));
String toname = cursor.getString(cursor.getColumnIndex("touser"));
String content = cursor.getString(cursor.getColumnIndex("content"));
String date = cursor.getString(cursor.getColumnIndex("date"));
String type = cursor.getString(cursor.getColumnIndex("type"));
}while(cursor.moveToNext());
}
假如游标到了第二个位置,现在取name 怎么判断与第一个位置中的name相同 展开
2个回答
展开全部
把读取的数据存起来就可以了~
ArrayList<HashMap<String, Object>> temp = new ArrayList<HashMap<String,Object>>();
if(cursor.moveToFirst()){
do{
HashMap<String, Object> map = new HashMap<String, Object>();
String name = cursor.getString(cursor.getColumnIndex("fromuser"));
String toname = cursor.getString(cursor.getColumnIndex("touser"));
String content = cursor.getString(cursor.getColumnIndex("content"));
String date = cursor.getString(cursor.getColumnIndex("date"));
String type = cursor.getString(cursor.getColumnIndex("type"));
map.put("fromuser", name);
//其他数据同
temp.add(map);
}while(cursor.moveToNext());
}
//读取数据
String name1 = temp.get(1).get("name").toString();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |