当前位置:   article > 正文

Android cursor遍历数据

android cursor遍历

数据存储为一行多列时

Person person = new Person();
double amount = 0;
if (cursor != null && cursor.moveToFirst()) {
	int indexOfPerson = cursor.getColumnIndex(Calculate.COLUMN_PERSON);
	int indexOfAmount = cursor.getColumnIndex(Calculate.COLUMN_AMOUNT);

	String personStr = cursor.getString(indexOfPerson);
	person = JSONObject.parseObject(personStr, Person.class);

	amount = cursor.getDouble(indexOfAmount);

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

数据存储为多行多列时

if (cursor != null && cursor.moveToFirst()) {
	Role[] roles = new Role[cursor.getCount()];
	int roleIndex = cursor.getColumnIndex(Role.COLUMN_ROLE);

	while (cursor.moveToNext()) {
		Role role = JSONObject.parseObject(cursor.getString(roleIndex), Role.class);
		roles[cursor.getPosition()] = role;
	}
	return roles;

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/122842?site
推荐阅读
相关标签
  

闽ICP备14008679号