Problems when I want to save remote data in a List with Volley

1

I'm creating a DialogFragment with radious options on Android. The options of the DialogFragment are obtained remotely through a server, through Volley. These options are saved in a List. When I call this method Acciones.attendancesPlayerToGame(gameID, getContext(),players) , which internally works perfectly, it never updates my List players, since the size of players is always zero.

MyDialogFragment

  public AlertDialog createRadioListDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    String gameID= getArguments().getString("gameID");

    List<JugadorView> players=new ArrayList<JugadorView>();
    Acciones.attendancesPlayerToGame(gameID, getContext(),players);
    final CharSequence[] items = new CharSequence[players.size()];
    for(int i = 0; i< players.size();i ++){
        String nombre= players.get(i).nombre;
        String apellidos = players.get(i).apellidos;
        String nombreComplet = nombre + " " + apellidos;
        items[i] = nombreComplet;
    }



more code
    }

When I put a breakpoint inside the Acciones.attendancesPlayerToGame method, internally to the List player the elements are added, but later in the MyDialogFragment class the list player is never updated.

attendancesPlayerToGame

public static void attendancesPlayerToGame(final String idGame,final Context context, final List<JugadorView> jugadorViewList) {
    final String URLLISTGROUP = "http://www.myweb.com/app/file.php";
    final StringRequest stringRequest = new StringRequest(Request.Method.POST, URLLISTGROUP,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {


                    try {
                        JSONArray jsonArray = new JSONArray(response);

                        for (int i = 0; i < jsonArray.length(); i++) {

                            JSONObject jsonObject = jsonArray.getJSONObject(i);


                            String emailJugador = jsonObject.getString("emailJugador");
                            String nombreJugador = jsonObject.getString("nombreJugador");
                            String apellidosJugador = jsonObject.getString("apellidosJugador");
                            String jugadorId = jsonObject.getStri

ng("jugadorID");


                                JugadorView jugadorView = new JugadorView(nombreJugador, apellidosJugador, emailJugador, jugadorId);

                                jugadorViewList.add(jugadorView);



                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show();
                    }
                }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<String, String>();
                params.put("idGame", idGame);

                return params;
            }

        };

        RequestQueue requestQueue = Volley.newRequestQueue(context);
        requestQueue.add(stringRequest);


    } 

Thank you very much in advance for your response.

    
asked by arisolarpower 16.10.2016 в 19:49
source

0 answers