Everything works correctly for me by only collecting the values of an array, but when I collect the data of the two that is what I want, I am missing data, as I can do it to have them in the same activity:
@Override
protected String doInBackground(String... url) {
urlPost = url[0];
try {
jsonObjectDesignPosts = JsonParser.readJsonFromUrl(urlPost);
postNumber = jsonObjectDesignPosts.getJSONArray("golesLocal").length();
jsonArrayDesignContent = jsonObjectDesignPosts.getJSONArray("golesLocal");
postNumber = jsonObjectDesignPosts.getJSONArray("golesVisitante").length();
jsonArrayDesignContent = jsonObjectDesignPosts.getJSONArray("golesVisitante");
sharedPreferences.edit().putString("DESIGN", jsonArrayDesignContent.toString()).apply();
designNombre_local = new String[postNumber];
designMinuto_local = new String[postNumber];
designNombre_visitante = new String[postNumber];
designMinuto_visitante = new String[postNumber];
for (int i = 0; i < postNumber; i++) {
designNombre_local[i] = Html.fromHtml(jsonObjectDesignPosts.getJSONArray("golesLocal").getJSONObject(i).getString("nombre")).toString();
designMinuto_local[i] = Html.fromHtml(jsonObjectDesignPosts.getJSONArray("golesLocal").getJSONObject(i).getString("minuto")).toString();
designNombre_visitante[i] = Html.fromHtml(jsonObjectDesignPosts.getJSONArray("golesVisitante").getJSONObject(i).getString("nombre")).toString();
designMinuto_visitante[i] = Html.fromHtml(jsonObjectDesignPosts.getJSONArray("golesVisitante").getJSONObject(i).getString("minuto")).toString();
}
} catch (IOException | JSONException e) {
e.printStackTrace();
designNombre_local = new String[0];
error = true;
}
return null;
}
@Override
protected void onPostExecute(String result) {
designs = new ArrayList<>();
if (designNombre_local.length != -1) {
for(int i=0; i<(designNombre_local.length); i++){
designs.add(new Goles(designNombre_local[i],designMinuto_local[i],
designNombre_visitante[i],designMinuto_visitante[i]));
}
}
if (error) {
Toast.makeText(getActivity(), "Error de conexión", Toast.LENGTH_LONG).show();
}
I noticed that it shows the number of items below, I mean, in the game they marked the premises 5 and the visitors 3, because it shows only three results of each team. What is the reason?