I have this piece of code:
private List<String> cachedRouteMarkers = new ArrayList<>();
private List<Route> cachedRoutes = new ArrayList<Route>();
public List<Route> getRoutes(DataBaseHelper db) {//Saca la lista de marcardores
Cursor nombreruta = db.nombreruta();
for (nombreruta.moveToFirst(); !nombreruta.isAfterLast(); nombreruta.moveToNext()) {//Va recorriendo la base de datos por el nombre de ruta
Cursor wp = db.waypoints(nombreruta.getString(0));//Extrae los waypoints
for (wp.moveToFirst(); !wp.isAfterLast(); wp.moveToNext()) {
cachedRouteMarkers.add(wp.getString(0));//Va añadiendo los waypoints
}
cachedRoutes.add(new Route(nombreruta.getString(0),cachedRouteMarkers,Color.RED));//Va añadiendo las rutas
cachedRouteMarkers.clear();
}
return cachedRoutes;
}
The getRoutes(DatabaseHelper db)
method extracts strings from a database and puts them in cachedRouteMarkers
. Then I'm creating an object of type Route
, using the above as an attribute and I'll store it in cachedRoutes
. I want the number of Strings of cachedRouteMarkers
in each Route
to remain fixed, but with each iteration it is modified.
How can I make it stay fixed and not change?
Thank you very much in advance:)