1. 程式人生 > >Android Cursor遍歷

Android Cursor遍歷

public List<PointBean> getAllPoints() {
		String sql = "select * from points";
		SQLiteDatabase db = helper.getWritableDatabase();
		List<PointBean> pointList = new ArrayList<PointBean>();
		PointBean point = null;
		Cursor cursor = db.rawQuery(sql, null);
		while (cursor.moveToNext()) {
			point = new PointBean();
			point.setPointName(cursor.getString(cursor
					.getColumnIndex("point_name")));
			point.setLongitude(cursor.getDouble(cursor
					.getColumnIndex("longitude")));
			point.setLatitude(cursor.getDouble(cursor
					.getColumnIndex("latitude")));
			pointList.add(point);
		}
		return pointList;
	}