Hello Good day I'm doing my first app and what happens is that the information that will be in the application, will be extracted from a database and if I have a connection with it.
I have a cycle for
with which I call several states to appear on the screen and only shows me the last data, that is not going through correctly, replaces the others by the latter.
Here is the code, your support would be of great help.
Thank you.
@Override
protected Void doInBackground(Void... voids) {
rutaList = new ArrayList<>();
conexionJson jOj = new conexionJson();
Turismo map = new Turismo();
try { JSONObject jsonObject = jOj.getJSONObjectFromURL("http://guanajuato.gob.mx/WSAppGto/enlace.php?metodo=pa_get_all_turismo");
JSONArray jsonA = jsonObject.getJSONArray("Resultado");
{
int id;
String nombre;
String descripcion;
Double latitud;
Double longitud;
String tipo;
String imagen;
int i = 0;
for ( i = 0; i < jsonA.length(); i++) {
JSONObject row = jsonA.getJSONObject(i);
id = row.getInt("idturismo");
nombre = row.getString("nombre");
descripcion = row.getString("descripcion");
latitud = row.getDouble("latitud");
longitud = row.getDouble("latitud");
tipo = row.getString("tipo");
imagen = row.getString("imagen");
switch (imagen) {
case "Dolores Hidalgo":
title = "http:\/\/doloreshidalgo.gob.mx\/images\/dolores-hidalgo-cin.png";
break;
case "Yurira":
title = "descarga.jpg";
break;
}
System.out.println(i);
System.out.println(nombre);
map.setId("1");
map.setNombre((String) nombre);
map.setDescripcion((String) descripcion);
map.setLatitud((Double) 0.0);
map.setLongitud((Double) 0.0);
map.setTipo((String) tipo);
map.setIdNombre("");
map.setImagen((String) imagen);
map.setDetalles("");
map.setImg(1);
rutaList.add(map);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
And in console if you give me the 3 names that I have in the database I / System.out: JSON:
> {"Resultado":[{"idturismo":1,nombre:"Dolores
> Hidalgo"},{"idturismo":2,"nombre":"yuriria",{"idturismo":3,"nombre":"San
> Miguel de Allende"
> I/System.out: 0
> I/System.out: Dolores Hidalgo
> I/System.out: 1
> I/System.out: yuriria
> I/System.out: 2
> I/System.out: San Miguel de Allende